error: no matching function for call to ‘QAction::QAction(const char [5])’

qt_4_21

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s