Qt Cannot open include file: 'QPrinter' - qt

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)

Related

Compiling libwebsocket with newest QT

It appears that libwebsocket is the only library that does not come with Qt, so I think I need to compile it and install it in my QT folder so I can use with other things.
I tried to compile libwebsocket and I got this error:
qwebsocket_p.h:65:10: fatal error: private/qobject_p.h: No such file or directory
#include <private/qobject_p.h>
I believe this is because the QT in my system is old. I have a QT installation in my home folder. How should I pass it to websocket?
If it were with cmake I'd have an idea, but I've heard here https://stackoverflow.com/a/49108604/10116440 that you cannot pass qt folder to qmake. Is there a way to pass to make?
I also tried doing this in cmake:
find_package(Qt5WebSockets REQUIRED)
find_package(Qt5 COMPONENTS Core Qml Quick Svg)
this way I can do cmake -DQt5_DIR=/home/lz/Qt5.11.2 . to set the Qt5 variable for everything except Qt5WebSockets, but the project fails to include <QWebSocket> anyway. If someone knows how to solve this, it'd also be good
private/qobject_p.h: No such file or directory
That means that the directory containing qobject_p.h was not added to the Include paths list. Make sure that your .pro has QT += core-private string.
I have a QT installation in my home folder. How should I pass it to websocket?
It should be enough to put the file named qt.confto the directory containing qmake.exe:
qt.conf
[Paths]
Prefix = <qt root>

Qt Creator: include directories

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.

Set Additional Include Directories in Qt Creator

I am using Qt Creator to rewrite my former project which is developed in Visual Studio. In this project I need to use an external library (gloox for xmpp).
Here's what I did in Visual Studio:
Add c:/dir1/ to the Additional Include Directories, that's where the tons of .h and .cpp files are.
Add c:/dir2/ in the linker setting, that's where the .lib file is.
I want to do the same thing in Qt Creator, so I added INCLUDEPATH += c:/dir1/ to the end of my .pro file, but when I qmaked again I still could not include anything from dir1 successfully.
#include <message.h>
C1083: Cannot open include file: 'message.h': No such file or directory
What should I do?
Based on the comment discussion, the problem seems to be that, after the INCLUDEPATH and potentially other relevant modifications, you forgot to properly re-run qmake.
This is necessary when dealing with QtCreator unfortunately due to the following long-standing issue:
Creator should know when to rerun qmake
I found the solution: copy everything in the .pro file and delete the .pro file. Then create a new .pro file and copy everything back, then execute qmake then run.

Can I get qmake -project to add LIBS += .... to my .pro file?

I have a project that uses Qt. So I have "qmake" make my Makefile from the .pro file. But Qmake can also make that .pro file: qmake -project . This worked until I needed to add an external extra library to my project.
I get lots of hits on google that tell me to add LIBS += ... to my project file, but I want to tell qmake -project something that causes it to add it for me. In effect of course I'll be doing it myself, but I don't think that it's proper that I am editing the generated project file.
If for example I add files to the project directory, I'll have to recreate it and add in the library again, or I'll have to manually add the files to the (almost completely computer-generated) project file. I'm now using a script to auto-generate the project file, and then add in the LIBS += directive, but is there a proper way to do this?
When you are developing without the Qt Creator IDE, unless the IDE includes by itself some automatic utilities, you must edit manually the .pro configuration file.
The generated .pro file is a skeleton file which YOU must fill in with the libraries that you need, then the qmake system figures out the other dependencies and compiles your project. It is a essentially a much better version of pkg-config of gtk + Makefiles.
When you add more source and resource files to your project then manually you must add them to the .pro file.
Example:
QT += core gui
TARGET = qtcp1
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
miwidget1.cpp \
lcdrange.cpp
HEADERS += mainwindow.h \
miwidget1.h \
lcdrange.h
FORMS += mainwindow.u
Alternately, you can issue qmake -project over and over again, but this can cause some unforseen accidents, since it includes everything that is in the current directory at the time, including the pre-processed files for conversion to standard C++ from QT dialect. This intermediate files must be erased (cleaned), before the remaking the project and the next make or can lead to tricky problems.
Using the official and free QT Creator IDE takes away most of this burden by adding automatically the new data to the .pro file and cleaning loose ends. Some other IDEs like Code::BLocks and Codelite provide some facilities for QT, but not to the level of QT creator. Some prefer to edit the .pro themselves for custom reasons, other like more other styles of IDEs, like Eclipse.
You should test the waters and decide by yourself what fits best to your needs.
ReEdited, to clarify a few things.

Qt OpenGL compile Static

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?

Resources