QT信号槽报错no matching member function for call to 'connect'
QT信号槽报错no matching member function for call to 'connect'
问题
connect(dynamic_cast<AnalyseWindow*>(parent),&AnalyseWindow::sigStart,timerRefresh,&QTimer::start,Qt::DirectConnection);
报错信息:
chartform.cpp:59:5: error: no matching member function for call to 'connect'
qobject.h:222:36: note: candidate function not viable: no known conversion from 'void (AnalyseWindow::*)()' to 'const char *' for 2nd argument
qobject.h:225:36: note: candidate function not viable: no known conversion from 'void (AnalyseWindow::*)()' to 'const QMetaMethod' for 2nd argument
qobject.h:242:43: note: candidate template ignored: couldn't infer template argument 'Func2'
qobject.h:283:13: note: candidate template ignored: couldn't infer template argument 'Func2'
qobject.h:322:13: note: candidate template ignored: couldn't infer template argument 'Func2'
qobject.h:274:13: note: candidate function template not viable: requires 3 arguments, but 5 were provided
qobject.h:314:13: note: candidate function template not viable: requires 3 arguments, but 5 were provided
qobject.h:481:41: note: candidate function not viable: requires at most 4 arguments, but 5 were provided
原因
有多种:
- 参数不是继承自
QObject
的对象,或者没有导入Qt
命名空间。 - 信号和槽的参数列表不匹配。信号的参数个数 >= 槽的参数个数且信号和槽的参数类型也必须匹配
- 函数指针类型不匹配。
- 在进行
connect
连接时,有可能会遇到无法匹配的候选函数。在这种情况下,可以通过使用QObject::connect
函数的第五个参数,来强制选择合适的函数。