I created a console application and have put this line in the .pro file:
CONFIG += c++11
Problem: if I use, for instance, std::to_string() in main.cpp, I have no problem, but if I create a new file/class (with QtCreator IDE) and I put to_string() in the class then I have a error that says that I have to use C++11. So it seems like the C++11 option only applies to main.cpp.
What could be the cause of this?
Related
I'm trying to create a GUI and i'm having issues with some header files that the program needs and uses.
If i click on the function in the main.cpp it takes me to the header file. But for some reason when i compile the program I get "undefined reference to " the function in main.cpp.
Ive tried to add the path of the include folder where the header file in the .pro file but it didnt work.
It seems to me that Qt sees the function but somehow it doesnt compile.
Any suggestions? Thank you
This is my solution to the case of “undefined reference to” error,
In .pro file append or modify this line:
QT += core gui sql printsupport network websockets
Maybe that's the same thing for you.
There is a similar description in the Qt document
Header: #include <QWidget>
qmake: QT += widgets
You can find which header file corresponds to which module
for some reason the compiler did not see the library that the header file needed. it was specified in the makefile but it didnt work.
in the .pro file i added
LIBS += -lmylib
and that fixed the issue. Thank you for your help
Including a header so the compiler can find the declarations of classes/methods/functions is one thing.
Adding source code or libs so that the definition of the declared facilities can be found by the linker is another.
I get "undefined reference to " the function in main.cpp
This is a linker error. You either haven't added your own source files to the project, or any third-part libs you use. Open the context menu of your project in the left Creator pane and select "Add existing file..." for the first case or "Add library..." for the second.
And in the next step you should spend some time reading the Creator manual as well as some basics about C++ and compiling in general. All beginner questions like the above have already been answered multiple times, you just have to search for them.
I tried to set up my Qt-Creator together with the MSVC compiler. It took a while to set up the PATH, but it's finally working. The only problem i have is, that i have to specify every single INCLUDEPATH, by either putting it into the .pro file and including like normal:
INCLUDEPATH += C:\Qt\5.4\msvc2013_64\include\QtCore\
#include <QtGlobal>
Or by going back one step and specifying the exact path in the .cpp include:
INCLUDEPATH += C:\Qt\5.4\msvc2013_64\include\
#include <QtCore/QtGlobal>
I already added the following line, which seems to do nothing for me (doesn't compile with the missing INCLUDEPATH tho):
QT += core
I work with the gcc compiler and Qt Creator at work and i can simply include with:
QT += core
#include <QtGlobal>
And i don't need to specify the exact INCLUDEPATH anywhere. I tried adding the INCLUDEPATH to my PATH environment-variable, but it does not seem to fix my problem.
How can I specify the location of the Qt-Headers in QtCreator without having to write the whole path in the .pro file or the base folder in the includes?
Okay, the answer is rather stupid.
The project I was testing with was an old one from my private repository and appareantly I created it as a non Qt-Project. The .pro file contained this line:
CONFIG -= qt
Which simply excluded all the Qt Headers.
I've got a problem with include in a qmake project. In my .pro file I've got:
INCLUDEPATH += "C:\OpenCV\build\include"
and in my cpp :
#include <opencv\cv.h>
The compiler indicates an error:
Cannot open include file: 'opencv\cv.h': No such file or directory
but if I write this in my cpp:
#include "C:\OpenCV\build\include\opencv\cv.h"
it works!
I build the project from within Qt Creator. What am I doing wrong?
You have to run qmake(build->run qmake) to validate changes in the pro file.
Qt creator Adding external library (still: Cannot open include file: 'GL/glew.h')
Your problem may be related to the fact that having backslashes in naked #include directives is undefined behavior.
Do the following.
Replace your include with
#include <opencv/cv.h>
Note the forward slash!
Remove the shadow build directory that Qt Creator has made for you. You will find it above the project directory, its name begins with build-.
Rebuild the project.
Note that this takes care of rerunning qmake.
here's one of my pro files:
# Blah Application
TEMPLATE = app
CONFIG += qt console staticlib debug_and_release
QT -= gui
QT += network sql xml
TARGET = blah
CONFIG(debug, debug|release){
DESTDIR = debug
LIBS += -L../../../lib/core/debug -lcore
} else {
DESTDIR = release
LIBS += -L../../../lib/core/release -lcore
}
DEPENDPATH += . ../../lib ../../../lib/core
INCLUDEPATH += . ../../lib ../../../lib/core
# Library files
HEADERS += mtBlahRTP.h
SOURCES += mtBlahRTP.cpp
# Input
HEADERS +=
SOURCES += main.cpp
The include path points to the RELATIVE directory of my lib files. mtBlahRTP.h and mtBlahRTP.cpp are in ../../lib
I have the same question, before building or running, you should qmake(Build=>qmake) it.
My configurations for INCLUDEPATH:
INCLUDEPATH+=D:\opencv\opencv\build\include
INCLUDEPATH+=D:\opencv\opencv\build\include\opencv
INCLUDEPATH+=D:\opencv\opencv\build\include\opencv2
I ran into a similar issue and what I found is that the QtCreator IDE is not re-reading the results of qmake and updating the "Cannot open" message. You need to close the offending file and re-open it - then you'll see that it no longer displays the error.
I had to do two steps: (re-)run qmake and rebuild the whole project - only then the INCLUDEPATH setting was considered correctly. (With QtCreator 3.5 and 3.6 (Qt 5.5 and Qt 5.6) on Windows.)
The only problem you are making is incorrectly linking the OpenCV library. The other answers given here may or may not work, but I have posted on another thread a surefire way to solve this problem using the "Add Library" wizard inside Qt Creator: https://stackoverflow.com/a/51914928/10245006
I was getting the error:
canserialcomm.o: In function `CanSerialComm::CanSerialComm()':
canserialcomm.cpp:(.text+0xc1): undefined reference to `vtable for CanSerialComm'
It turns out that the cause was it wasn't able to find canserialcomm.h where that constructor is declared. This was despite me having INCLUDEPATH in the project file point to the directory containing that header file:
INCLUDEPATH += . \
..
What I had to do to fix this is explicitely specify the header file; I added:
HEADER += ../canserialcomm.h
You should use double backslashes when in windows for qt creator with msvc. like this:
INCLUDEPATH += C:\\libcurl\\libcurl-vc-x64-release-dll-ipv6-sspi-winssl\\include
this will fix the problem.
Under windows you have to eliminate the -I before each directory that is added into the INCLUDEPATH variable.
For example:
Under windows:
INCLUDEPATH += "C:\lib\boost_1_61_0" (back-slash)
Under linux & mac:
INCLUDEPATH += -I"$$(HOME)/lib/boost_1_61_0" (note the -I and forward-slash)
I'm not sure whether it depends on different qmake version or not. But after finishing qmake command, I check the Makefile and the double -I is the issue.
You need to do several things. Fist, in the .pro file, you need quotation marks two backslashes at a time, like this:
INCLUDEPATH += "C:\\OpenCV\\build\\include\\opencv\\cv.h"
You alse need a frontslash in the #include in your .cpp file like this:
#include <opencv/cv.h>
When you've done this, delete the build folder. This is the folder with a very complicated name of the type build-untitled-Desktop_Qt_5_7_0_MSVC2015_32bit-Release. Then, in the Build menu, press "Run qmake". When you've done all this, it should compile fine.
Somehow it did not work for when I had several INCLUDEPATH +=.
When I combined the stuff into a single on it suddenly worked.
I am new to Qt. Downloaded source code for a Qt application of SourceForge, and tried to build and run it. After working through a few similar problems by adding QT += statements to .pro files, I am stuck on this one:
On attempting to build in Qt Creator, I get errors saying
error: C1083: Cannot open include file: 'QPrinter': No such file or directory
I tried adding QT += printsupport to the .pro file, cleaning, and rebuilding, but that gives this error
Error: dependent '..\..\..\..\..\..\..\..\..\..\..\Qt\Qt5.1.1\5.1.1\msvc2012_64\include\QtPrintSupport\qtprintsupportglobal.h' does not exist."
When I go to C:\Qt\Qt5.1.1\5.1.1\msvc2012_64\include\QtPrintSupport, qtprintsupportglobal.h IS THERE!
You have to add QPrinter Support to your project's .pro file:
QT += printsupport
In my case the solution was to
Delete the shadow build directory and build again
after adding printsupport, as #KubaOber suggests in the comments.
Easy mistake to make: After you edit your .pro
QT += printsupport
You have to SAVE the file before your .h will be aware of it.
Because QMake will eventually be dropped in favor of CMake, here's the solution for CMake users:
Pass PrintSupport to the find_package call, to the right side of COMPONENTS, like in this example:
find_package(Qt5 ${QT5_MIN_VERSION} REQUIRED COMPONENTS Core Gui Qml QuickControls2 PrintSupport)
I wrote a small app with qt and opengl (code) and I want to compile it static now.
So i downloaded Qt library and compile it static using this guide.
I added a line CONFIG += static to the pro file cd to the project location and hit:
make clean
qmake -config release
make
but I am getting several undefined references like:
qpixmapdata_gl.cpp:-1: error: undefined reference to `_imp___Z14qt_defaultDpiYv'
What I am doing wrong? Do I need to add the libs to the pro file? How do I do this and more important what libs should I use?
I tried something like this with no result:
LIBS += C:\Qt\4.7.3\bin\QtOpenGL4.dll
I see that symbol is defined in qfont.cpp, so it should be there. I would try to add:
QT += gui
in your .pro file. And I suppose you need:
QT += core
also.
EDIT: Try also to check that the symbol is included in the libQtGui.lib and the line used to compile.
Are you using the same compiler also? The mangling reported seems that of gcc. Did you compile Qt libraries with mingw or nmake?