Configuring the GCC compiler switches in Qt, QtCreator, and QMake
It boils down to reading the manual. Instead of using CXXFLAGS
in the .pro file, you need to use QMAKE_CXXFLAGS
as in:
main.cpp:
#include <cinttypes>
int main() { return 0; }
main.pro:
SOURCES += main.cpp
QMAKE_CXXFLAGS += -std=c++0x
How to add options to gcc in qt creator?
Add LIBS += -lGL -lglut
to your .pro
file.
QMAKE_CXXFLAGS
is for C++ compiler flags like -std=C++0x
How to manually set GCC as the compiler in QtCreator?
Define a compiler in Tools>Options>Build & Run>Compilers, then switch to the kits tab and add that compiler to the kit you want to use.
The process is described in detail in the manual:
https://doc.qt.io/qtcreator/creator-tool-chains.html for the compiler setup and https://doc.qt.io/qtcreator/creator-targets.html is about the kits.
How to enable custom gcc parameters in Qt Creator?
You need to add QMAKE_CXXFLAGS += -std=c++0x to your .pro file.
How to set qmake to C++14 with recent MinGW?
The version of Qt that you're using doesn't explicitly support the compiler you're using. You can do either one of the following:
Set both
QMAKE_CXXFLAGS_CXX14
andQMAKE_CXXFLAGS_GNUCXX14
in your project:win32-g++ {
QMAKE_CXXFLAGS_CXX14 = -std=c++14
QMAKE_CXXFLAGS_GNUCXX14 = -std=c++14
}Edit the default values of those two variables as above, in
mkspecs/win32-g++/qmake.conf
within your Qt installation folder.Add a new
mkspec
copied fromwin32-g++
, targeting your compiler, and build your Qt using it. All the project that use that Qt will then behave correctly w.r.t. C++14 support.
How to use C++11 in Qt creator 4.8
This is the simplest approach to creating a qt project:
- Open a new terminal and create an empty folder
Foo/
in your Desktop:~$ cd Desktop; mkdir Foo/
- Change to that folder:
~$ cd ~/Desktop/Foo
- Create 2 files:
~$ touch Foo.pro main.cpp
- If you have exported the correct paths in your
.profile
or.bashrc
, then you can type~$ qtcreator
in your terminal to run qt. Otherwise, click on the QtCreator App from the applications. - Go to
File -> Open project
and select theFoo.pro
file. - Keep the default paths to debug and release mode, and hit continue, or ok (can't remember exactly)
- You should have the
Foo.pro
file open in Qt. Now enter the following lines in the Foo.pro file and hit save (Ctrl+S).
CONFIG += c++11 console
TARGET = My_Foo
SOURCES += main.cpp
- Once you hit save, you should see the main.cpp file on the left pane that lists the project files. If so, click on the Projects button (spanner tool) on the left menu.
- Under the
Build option
, untickshadow build
and under theRun option
, untickRun in terminal
. - Go back to your main.cpp file and type a simple hello program. Press
Ctr+S
(to save),Ctrl+B
(to build the project) andCtrl+R
(to run).
Up until step 7, you can do it using the GUI, by selecting Create new Project and then select console application. Btw, on mac use Cmd instead of Ctrl.
Also make sure you have the correct compilers setup. (https://doc.qt.io/qtcreator/creator-tool-chains.html)
How to change/configure desired compiler in Qt creator? i.e. switch between MSVC/Mingw or g++/clang++
Following is the way with Qt 5.9:
- While configuring a new project, select only those compilers/kits which are required;
- For 64-bit system, get the latest MinGW and install in a suitable path; While installing MinGW64, you may select "posix threads", and not "win32 threads" to allow threading related libraries
- Go to
Tools > Options > Build & Run > Compilers
and add a manual C++ compiler. Choose the path of where you installedC:/MinGW64/bin/g++.exe
(name it something like "MinGW64"); Similarly you may add C compiler as well withC:/MinGW64/bin/gcc.exe
; Click 'Apply' - In the same dialog box, select the
Debuggers
tab and similarly addC:/MinGW64/bin/gdb.exe
(name it like "MinGW64 Debugger); Click 'Apply' - In the same dialog box, select the
Qt Versions
and add a new Kit withMinGW64
like name; However I couldn't find an appropriateqmake.exe
for it; Hence, I decided to use the sameqmake.exe
, which came with built-in 32 bit MinGW within Qt package (not sure about this as of now) - In the same dialog box, now select the
Kits
tab and add a newManual kit
; You may also follow the way the default MinGW32 bit compiler is configured; ConfigureCompiler
,Debugger
andQt Version
for this newly named kit; Click 'Ok' - On the left pan of Qt creator, click on "Projects" tab, and go to "Build & Run" option there; To avoid confusion, you may disable all the kits which are not required; Just keep the relevant kit and click "Build" with either "Debug" or "Release" setting
Related Topics
Compare Double to Zero Using Epsilon
Visual C++ 2008 Express Download Link Dead
The New Keyword "Auto"; When Should It Be Used to Declare a Variable Type
What Exactly Is Streambuf? How to Use It
Easy Rule to Read Complicated Const Declarations
How to Convert from Int to Char*
Why Do We Require Requires Requires
Reset Cuda Context After Exception
Heap Corruption While Using Createwindowexw
Compute Objects Moving with Arrows and Mouse
Std::Function and Std::Bind: What Are They, and When Should They Be Used
What Is Std::Decay and When It Should Be Used
How to Check That an Element Is in a Std::Set
Differencebetween Exit() and Abort()
Compiling with G++ Using Multiple Cores
How to Print to Console When Using Qt
When to Make a Type Non-Movable in C++11
Why Is My Object Not Being Copied When Move Constructor Is Deleted