Qt:no matching function for call to (类名)::connect()的错误原因总结
2016-08-12 21:42
603 查看
最近初学Qt,在做项目的过程中遇到 E:\QT Project\WinCalculater\mainwindow.cpp:132: 错误:no matching function for call to 'MainWindow::connect(MyButton*&, void (MyButton::*)(), MainWindow* const, const char*)' 的问题,然后我就上网查错误的原因,但是查到的答案都没有解决我的问题,后来自己发现了问题所在,故在此与大家分享下。
错误代码:
connect(but0,&MyButton::clicked,this,SLOT(button1()));
错误原因:
这样不满足connect()五个重载函数的参数要求,也就是参数列表出了问题。
在 Qt 5 中,
QMetaObject::Connection connect(const QObject *, const char *,
const QObject *, const char *,
Qt::ConnectionType);
QMetaObject::Connection connect(const QObject *, const QMetaMethod &,
const QObject *, const QMetaMethod &,
Qt::ConnectionType);
QMetaObject::Connection connect(const QObject *, const char *,
const char *,
Qt::ConnectionType) const;
QMetaObject::Connection connect(const QObject *, PointerToMemberFunction,
const QObject *, PointerToMemberFunction,
Qt::ConnectionType)
QMetaObject::Connection connect(const QObject *, PointerToMemberFunction,
Functor);
我的错误是混用了第一个和第四个重载函数: 信号&MyButton::clicked是PointerToMemberFunction类型的,槽函数SLOT(button1())是const
char * 类型的,所以会报错。
因为我的button1()是自定义的private slots:的函数,所以我把[b]SLOT(button1())换成&MainWindow::button1就可以了。
[/b]
错误代码:
connect(but0,&MyButton::clicked,this,SLOT(button1()));
错误原因:
这样不满足connect()五个重载函数的参数要求,也就是参数列表出了问题。
在 Qt 5 中,
QObject::connect()有五个重载:
QMetaObject::Connection connect(const QObject *, const char *,
const QObject *, const char *,
Qt::ConnectionType);
QMetaObject::Connection connect(const QObject *, const QMetaMethod &,
const QObject *, const QMetaMethod &,
Qt::ConnectionType);
QMetaObject::Connection connect(const QObject *, const char *,
const char *,
Qt::ConnectionType) const;
QMetaObject::Connection connect(const QObject *, PointerToMemberFunction,
const QObject *, PointerToMemberFunction,
Qt::ConnectionType)
QMetaObject::Connection connect(const QObject *, PointerToMemberFunction,
Functor);
我的错误是混用了第一个和第四个重载函数: 信号&MyButton::clicked是PointerToMemberFunction类型的,槽函数SLOT(button1())是const
char * 类型的,所以会报错。
因为我的button1()是自定义的private slots:的函数,所以我把[b]SLOT(button1())换成&MainWindow::button1就可以了。
[/b]
相关文章推荐
- Qt error ------ no matching function for call to QObject::connect(QSpinBox*&, <unresolved overloaded function type>, QSlider*&, void (QAbstractSlider::*)(int))
- 【C++错误处理】no matching function for call to transform
- C++ STL string 大小写转换时的 no matching function for call to ‘transform 错误
- C++常见错误之:no matching function for call to transfor
- iOS linker错误之no matching function for call to ’recvfrom’
- 【C++错误处理】no matching function for call to transform
- error: no matching function for call to 'MainWindow::connect(*&, ...)
- C++ STL string 大小写转换时的 no matching function for call to ‘transform 错误
- C++常见错误之:no matching function for call to transform
- C++中错误no matching function for call to transform
- G++编译错误 no matching function for call to '_tag_data_value::StringAddLen(std::string, int, int)
- 【求助】 no matching function for call to `strcpy(std::string&, char*&)'
- no matching function for call to ‘transform
- error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
- no matching function for call to 'strstr(stdstring&, const char [4])'
- [c++]no matching function for call to ‘sort(…)......
- error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
- no matching function for call to
- error: no matching function for call to ‘ptr_fun(<unresolved overloaded function type>)’
- error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)