报错信息:
QObject::connect: No such slot MainWindow::(onXXX()) in …\MainWindow.cpp:150
QObject::connect: (sender name: ‘actionXXX’)
QObject::connect: (receiver name: ‘MainWindow’)
代码如下:
connect(ui->actionXXX, SIGNAL(triggered()), this, SLOT(onXXX()));
除了检查名称有没有写错;ui文件写没写对;函数有没有定义;是不是QObject子类外,这次报错的原因是:
SLOT(onXXX());多写了个括号!!!
也就是说,正确写法:
connect(ui->actionXXX, SIGNAL(triggered()), this, SLOT(onXXX()));
错误写法:
connect(ui->actionXXX, SIGNAL(triggered()), this, SLOT((onXXX())));
真的吐了,万万没想到这也能犯错