Configuring the Gcc Compiler Switches in Qt, Qtcreator, and Qmake

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:

  1. Set both QMAKE_CXXFLAGS_CXX14 and QMAKE_CXXFLAGS_GNUCXX14 in your project:

    win32-g++ {
    QMAKE_CXXFLAGS_CXX14 = -std=c++14
    QMAKE_CXXFLAGS_GNUCXX14 = -std=c++14
    }
  2. Edit the default values of those two variables as above, in mkspecs/win32-g++/qmake.conf within your Qt installation folder.

  3. Add a new mkspec copied from win32-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:

  1. Open a new terminal and create an empty folder Foo/ in your Desktop: ~$ cd Desktop; mkdir Foo/
  2. Change to that folder: ~$ cd ~/Desktop/Foo
  3. Create 2 files: ~$ touch Foo.pro main.cpp
  4. 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.
  5. Go to File -> Open project and select the Foo.pro file.
  6. Keep the default paths to debug and release mode, and hit continue, or ok (can't remember exactly)
  7. 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

  1. 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.
  2. Under the Build option, untick shadow build and under the Run option, untick Run in terminal.
  3. Go back to your main.cpp file and type a simple hello program. Press Ctr+S (to save), Ctrl+B (to build the project) and Ctrl+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:

  1. While configuring a new project, select only those compilers/kits which are required;
  2. 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
  3. Go to Tools > Options > Build & Run > Compilers and add a manual C++ compiler. Choose the path of where you installed C:/MinGW64/bin/g++.exe (name it something like "MinGW64"); Similarly you may add C compiler as well with C:/MinGW64/bin/gcc.exe; Click 'Apply'
  4. In the same dialog box, select the Debuggers tab and similarly add C:/MinGW64/bin/gdb.exe (name it like "MinGW64 Debugger); Click 'Apply'
  5. In the same dialog box, select the Qt Versions and add a new Kit with MinGW64 like name; However I couldn't find an appropriate qmake.exe for it; Hence, I decided to use the same qmake.exe, which came with built-in 32 bit MinGW within Qt package (not sure about this as of now)
  6. In the same dialog box, now select the Kits tab and add a new Manual kit; You may also follow the way the default MinGW32 bit compiler is configured; Configure Compiler, Debugger and Qt Version for this newly named kit; Click 'Ok'
  7. 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



Leave a reply



Submit