Qt Creator warning: ‘auto’ changes meaning in C++11; please remove it

Just wrapped up section 3 of my Qt C++ beginner GUI course! Boy, this course is fun! I really appreciate the instructor taking the time to show 3 different ways to do things, and explaining why one might be more useful than others in different situations. I did run into a couple of errors though:

warning: ‘auto’ changes meaning in C++11; please remove it

And this one, too:

error: no matching function for call to ‘Widget::connect(QPushButton*&, void (QAbstractButton::*)(bool), Widget::Widget(QWidget*)::<lambda()>)’
});

Both of these are related, so I thought I’d bundle them together in this post. Apparently, GCC for Linux, while super smart, is so flexible that you can, of course, use different C++ standards, however, by default, it uses the OLDEST one. WHY?! So, in Qt creator, you have to tell it specifically to use the latest C++ standard, like so:

#-------------------------------------------------
#
# Project created by QtCreator 2018-06-22T09:40:37
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = section_3_18
TEMPLATE = app


SOURCES += main.cpp\
        widget.cpp

HEADERS  += widget.h

FORMS    += widget.ui

QMAKE_CXXFLAGS = -std=c++14
QMAKE_LFLAGS = -std=c++14

Those last two QMAKE lines are the ones I added. You can set them to any standard you like that is in your compiler, such as c++11, c++14, c++1z (well, on mine that is the 2017 standard, some newer ones may have c++17). Adding those two lines and saving the file will fix it.

The second error was caused because I had Qt4 and Qt5 installed. Obviously, you should use the newest one available to you. So, I had to click:

Tools->Options->Kits->Desktop

qt_3_17

And choose the latest Qt5 version, rather than the default of the lower Qt4 version. It took me a while of web browsing to figure this out, so hopefully this will save someone else some time!

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