While working through section 4 of my Qt GUI creator course, I ran into an interesting error:
/home/alaskalinuxuser/Documents/qt_course/section_4_21_qmainwindow/mainwindow.cpp:19: error: no matching function for call to ‘QAction::QAction(const char [5])’
QAction * quitAction = new QAction(“Quit”);
^
What made the error interesting was that my code mirrored the instructors to a T:
// Now some QActions….
// Quiting
QAction * quitAction = new QAction(“Quit”);
// And connect it.
connect (quitAction,&QAction::triggered,[=](){
QApplication::quit();
});
However, after reading up a bit on it, I needed to add “this” to my QAction, like so:
// Now some QActions….
// Quiting
QAction * quitAction = new QAction(“Quit”, this);
// And connect it.
connect (quitAction,&QAction::triggered,[=](){
QApplication::quit();
});
Once I did that, it was smooth sailing. I don’t know for sure, it may be because the instructor was using Windows with MinGW and I am using Linux with GCC, or if it is a Qt version difference. Either way, if you run into this error, here’s the quick fix!
Linux – keep it simple.
Just got this myself and I am on Windows with MinGW.
Thanks for the fix!