QtCreator Cmake C++17 Features - c++

So here I am, compiling my CMake-based C++ Projects in my terminal like there's not tomorrow with gcc-7.2.0 on Xubuntu 16.04 (via ppa)
Everything works fine and the new features add considerable value to my codebase.
However, trying to compile the very same project in qtcreator with the same compiler yields me errors like the following
: error: expected ‘)’ before ‘;’ token
if (auto event = events_.find(eventName); event == end(events_)) {
^
: error: ‘else’ without a previous ‘if’
} else {
^
if trying to compile initializer-ifs. I tried to manually pick gcc-7 in the build&run section in qtCreators options but without success. So my question is this:
What do I have to adjust in the IDE to make it conform to this latest standard?

If you're compiling Cmake projects in Qt creator, just be sure there is a line like this in your CMakeLists.txt:
set(CMAKE_CXX_STANDARD 17)
To use gcc-7.2.0, be sure it is listed in the Compilers tab of the Build & Run section in Tools/Option. Then, in Kits tab, select the kit you configured your project with, and select gcc-7.2.0 as the the kit's compiler.
If you're using qmake, instead, add this line to your pro file:
QMAKE_CXXFLAGS += -std=c++17

Related

unrecognized command line option '-Zc:__cplusplus' and unrecognized command line option '-permissive-'

I am trying to run and debug Qt6 widget application in clion.
I tried the things that u would get when do a simple search but no success.
Recently my friend told my to do this :
Add "C:\Qt\Tools\mingw810_64" to toolchain environment like this :
now when I create a Qt widget project like this :
I get these error :
Problems were encountered while collecting compiler information:
g++.exe: error: unrecognized command line option '-Zc:__cplusplus'
g++.exe: error: unrecognized command line option '-permissive-'; did you mean '-fpermissive'?
What should I do now ?
Why doesn't it recognize these options ?
I cannot change g++.exe file (or can I?) What can do about it?
I have been struggling to manage to run and debugg Qt6 project on clion the past few weeks.
God bless anyone who help me to do this.
Please Help!
The problem is that you use MSVC-build of Qt and not the MinGW one. Update your CMakeLists.txt file:
set(CMAKE_PREFIX_PATH $ENV{QTDIR})
the environment variable QTDIR is set to Qt MinGW path (e.g. D:\Qt\6.2.3\mingw_64).
Don't forget to add the corresponding directory bin (%QTDIR%\bin) to the path environment variable.

Qt creator could not parse stddef.h --> incorrect code completion and highlighting

I am developing a QT GUI for my application using QT Creator (4.11.0).
Recently, our IT updated my OS to Ubuntu 20.04 (from 18.04) - maybe the error is related to that.
I have not touched to project in some month but yesterday wanted to continue developing it.
However, within the IDE there are now thousands of errors highlighted at almost every line of my code. (with highlighted I mean that there is this red background and a red dot beside the line number)
On the very top, it says:
Warning: The code model could not parse an included file, which might lead to incorrect code completion and highlighting, for example.
cstddef:50:10: fatal error: 'stddef.h' file not found
...
The errors that are listed in the IDE are very wired like:
type `QMainWindow`is not a direct or virtual base of `MainWindow` (my class is called `MainWindow`)
I'm pretty sure it is not related to my code:
the code compiles and works fine - it is really just the IDE that is highlighting errors at every line of my code.
I have the same code on a Windows Computer and there no errors are listed in the IDE.
even if I start a brand new QT Widget project the errors appear within the template code provided by the QT Creator.
Since the GCC version changed with the update of the OS, I thought maybe I have to define a new KIT but this also did not help.
Is there anything I can do to fix the issue?
Do I have to reinstall the QT Creator?
I know, pictures are not very well-liked but here I think it might help to understand what I mean with "IDE is highlighting errors":
1. First
~/.profile :
CPATH="/usr/include/clang/10/include:$CPATH"
C_INCLUDE_PATH="/usr/include/clang/10/include:$C_INCLUDE_PATH"
CPLUS_INCLUDE_PATH="/usr/include/clang/10/include:$CPLUS_INCLUDE_PATH"
export CPATH
export C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH
maybe /usr/include/clang/10/include see in you file system.
2. Second
Logout / login.
3. Third
Specifying Build Settings (Projects -> Build -> in every config build) in Build Environment section: [unset] CPATH, C_INCLUDE_PATH and CPLUS_INCLUDE_PATH
or [edit] replace this variable with the necessary values
I fixed this issue by sudo apt install clang-8.
Source: https://bugs.launchpad.net/ubuntu/+source/qtcreator/+bug/1890434

Qt web assembly: configure kit

I want to test out QT WebAssembly for my scientific program.
Therefore, I installed emscripten.
$em++ --version
returns
emcc (Emscripten gcc/clang-like replacement) 1.38.30 (commit a5082b232617c762cb65832429f896c838df2483)...
Then I installed Qt using the Qt WebInstaller.
In my installation directory I have a wasm_32 folder which contains bin and qmake:
$ ~/Qt_web/5.13.2/wasm_32/bin/qmake --version
return
QMake version 3.1
Using Qt version 5.13.2 in /home/myName/Qt_web/5.13.2/wasm_32/lib
However, when I start Qt creator, click on Projects I see a Kit called: Qt 5.13.2 WebAssembly but I cannot select it (it is grayed out).
When I click on manage Kits I saw that there is no C and C++ compiler selected for Qt 5.13.2.WebAssembly.
I also get an warning when I change to Qt Versions. The warning says:
ABI detection failed: Make sure to use a matching compiler when building. No qmlscene installed.
This is a list of all compilers which are selectable:
Question:
I do not really understand what emscripten has to do with all that. Is emscripten a compiler? If yes should it have been auto-selected by the Qt 5.13.2 WebAssembly kit?
How does a proper Qt WebAssembly kit look like?
If I select gcc as my compiler I get an error saying:
/home/myName/Qt_web/5.13.2/wasm_32/plugins/platforms/libqwasm.a:-1: error: error adding symbols: File format not recognized
EDIT:
When I open the qt maintenance tool and look at the installed packages I get the following:
EDIT2:
After changing to Qt Creator 4.11.0-beta2 (4.10.83) I was able to follow parts of this description. I was able to select the Plugin, but I still can not change the Device type.
Maybe it has to do with this error that I get now:
EDIT3:
seems as if my emscripten compiler has some problems.
Is the compiler located in:
emscripten/emsdk/clang/e1.38.30_64bit/clang++
emscripten/emsdk/clang/e1.38.30_64bit/clang
One thing I noticed is that If I use add in QtCreator >> Kits >> Compilers and I select Add >> WebAssembly >> C It generates a new entry in Manual >> C++ >> Emscripten Compiler and not in Manual >> C >> Emscripten Compiler. Is this a problem?
EDIT
This is how my Compilers page looks like:
You need to copy the .emscripten file from emsdk directory to your home (/home/myUsername).
You need to fix the paths in the file manually (See example below).
Notice that .emscripten file , at least in the version (1.39.8) i am using, is a python script (maybe a bug?)
example file before edit:
import os
emsdk_path = os.path.dirname(os.environ.get('EM_CONFIG')).replace('\\', '/')
NODE_JS = emsdk_path + '/node/12.18.1_64bit/bin/node'
LLVM_ROOT = emsdk_path + '/upstream/bin'
BINARYEN_ROOT = emsdk_path + '/upstream'
EMSCRIPTEN_ROOT = emsdk_path + '/upstream/emscripten'
TEMP_DIR = emsdk_path + '/tmp'
COMPILER_ENGINE = NODE_JS
JS_ENGINES = [NODE_JS]
after edit:
import os
emsdk_path = os.path.dirname(os.environ.get('EM_CONFIG')).replace('\\', '/')
NODE_JS = '/home/myUsername/node/12.18.1_64bit/bin/node'
LLVM_ROOT = '/home/myUsername/upstream/bin'
BINARYEN_ROOT = '/home/myUsername/upstream'
EMSCRIPTEN_ROOT = '/home/myUsername/upstream/emscripten'
TEMP_DIR = '/home/myUsername/tmp'
COMPILER_ENGINE = NODE_JS
JS_ENGINES = [NODE_JS]
When above steps are completed qt creator was able to detect the Emscripten Compiler with no errors.
Have you try in the kits tab to set your compiler with this values?
Compiler:
C compiler x86 64 e1.38.27_bit
C++ compiler x86 64 e1.38.27_bit
Qt version:
path to you qmake built with webassembly, for example webassembly binaries or your custom binaries.
Qt mkspec:
wasm-emscripten
Hope this information helps, if you face any other problem let me know.

QT project error: Unknown module in QT: widget

I installed the Qwt library (osx) and added it to my Qt project. After executing:
qmake -set QMAKEFEATURES ${QWT_ROOT}/features
I got the project build error:
QT project error: Unknown module in QT: widget
I removed the Qwt library from my project and system but the error is still existing. I also tried to reinstall Qt 5.2.1 and removed all user settings but still the same problem. To check if the property is still there I executed:
qmake -query QMAKEFEATURES
which returned:
**Unknown**
therefore this should not be the problem.
The compiler gives the following output:
ASSERT: "fileName.isEmpty() || isAbsolutePath(fileName)" in file /work/build/qt5_workdir/w/s/qtbase/qmake/library/ioutils.cpp, line 61
I found out there is a bug report in QT:
https://bugreports.qt-project.org/browse/QTBUG-29642?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
As I entered the command:
qmake -query
without an argument, it output that the property QMAKEFEATURES was still set:
QMAKEFEATURES:/usr/local/qwt-6.1.1-svn/features
Finally invoking:
qmake -unset QMAKEFEATURES
solved the problem.

When compiling get error: 'QtGui/QAction' file not found #include <QtGui/QAction>

I just installed Mac OS X 10.8.3 and Qt Creator 3, XCode, and XCode command line tools. I'm trying to compile a project that works on another computer but each time I go to "build all" I get error: 'QtGui/QAction' file not found
in #include <QtGui/QAction>
I tried adding the second and third line in the .pro file but it didn't help
QT += core gui opengl
CONFIG += qt
QT += gui
TARGET = BasicOpenGL
TEMPLATE = app
UPDATE: I also tried this .pro file and it didn't work
QT += core gui opengl
QT += widgets
TARGET = BasicOpenGL
TEMPLATE = app
I should say this is my first time attempting development on mac.
Compile Output from Qt
Versions/A/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/AGL.framework/Headers -I. -I. -F/Users/john/Qt/5.2.0/clang_64/lib -o mainwindow.o ../Framework/mainwindow.cpp
In file included from ../Framework/mainwindow.cpp:2:
../Framework/ui_mainwindow.h:14:10: fatal error: 'QtGui/QAction' file not found
#include <QtGui/QAction>
^
1 error generated.
make: *** [mainwindow.o] Error 1
15:51:32: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project BasicOpenGL (kit: Desktop Qt 5.2.0 clang 64bit)
When executing step 'Make'
UPDATE: I got it to work but with all the screwing around I'm not exactly sure what did it. I started with a fresh mac image, installed system updates, installed xcode, installed xcode command line tools, installed QT Creator 3.0, installed QT libraries 4.8.1, setup the compilers in QT Creator.
Try doing a make clean followed by a make. I had this exact problem on a Windows 7 system, and this is what worked for me.
In Qt5, QAction header is in QtWidgets include sub-directory, not in QtGui (that's true for Qt4). Though you don't actually need to specify include sub-directories since qmake will handle that for you. You just need to add QT += widgets to your .pro file.
Set the version to Qt5, change all #include<QtQui/*>s into #include<QtWidgets/*>.
And add QT += widgets in your .pro file.
Rebuild the project, when you get the error again, tap into the error message, and change the #include<QtQui/*>s into #include<QtWidgets/*> too.
Some answers here say that you have to change include from <QtGui/QAction> to <QtWidgets/QAction>.
It was the case when you compile under QT-5. But after QT-6 was released you have to do the opposite in QT-6 application.
Now you have to change <QtWidgets/QAction> to <QtGui/QAction>, because now QAction is located in QtGui folder in QT-6.
Although my answer is not related to your very old question, as you had QT-4 problem, still your question pops up first in Google hence I'm posting my answer for those StackOverflow visitors who have same problem but with compiling QT-5 project under QT-6, as I did.