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>
Related
I use Qt with CMake because CMake integrates with my team's work easier than my own. I have frequently encountered an error along the lines of
ui_*.h: No such file or directory
Usually when my project already has a ui_*.h file to start with it will just modify that .h file. I do use the below commands in my CMake file, so it should be wrapping my .ui file with the appropriate ui_*.h file.
qt4_wrap_ui (mainwindow mainwindow.ui)
target_linked_library (mainwindow ${QT_LIBRARIES})
But sometimes that doesn't work and I have to completely rebuild the entire ui_*.h file. What am I doing wrong?
For anyone having this problem in the future. I pretty much followed the demo here.
http://doc.qt.io/qt-5/cmake-manual.html
Adding, the following line to the CMakeLists.txt should get rid of this problem.
set(CMAKE_AUTOUIC ON)
From the CMake documentation at
https://cmake.org/cmake/help/v3.0/prop_tgt/AUTOUIC.html
AUTOUIC is a boolean specifying whether CMake will handle the Qt uic code generator automatically, i.e. without having to use the QT4_WRAP_UI() or QT5_WRAP_UI() macro. Currently Qt4 and Qt5 are supported.
One small note, this property is available in CMake versions 3.0.2+. So below that, #rbaleksandar's solution should be more appropriate.
Hope that helps.
The quick solution is to use UIC. In bash navigate to the directory containing your *.ui file and run (for the mainwindow.ui example)
uic mainwindow.ui -o ui_mainwindow.h
and then move the newly generated ui_mainwindow.h file to your build directory.
mv ui_mainwindow.h ../build_Qt_4_8_5-Debug/
You shouldn't see the 'No such file or directory' error anymore and can confidently move on to the many other wonderful errors to find in the world of Qt with CMake.
If I remember correctly you actually have to add your UI files to the add_executable(...) like this:
qt4_wrap_ui(UI_HEADERS mainwindow.ui ...) # Add all UI files here like you've done it
...
add_executable(${PROJECT_NAME} ${SRC} ${UI_HEADERS}) # Add them to the executable
...
After all UI files are actually converted to header and source files, which naturally have to be compiled along with the rest of your code.
Building with CMake seems to have an error in
if(CMAKE_VERSION VERSION_LESS "3.7.0")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
endif()
remove if in your CMakeLists.txt like this:
set(CMAKE_INCLUDE_CURRENT_DIR ON)
This works in my system with CMake 3.12.1 and Windows 10.
when the ui files are stored in a different location the CMAKE_AUTOUIC_SEARCH_PATHS can be set to include the custom locations so that the CMAKE_AUTOUIC option will find the ui files.
None of the previous answers have helped me.
I tried Ctrl + RMB on #include "./ui_mainwindow.h" in Qt Creator and after that the error did not appear since.
Few details to mention:
set(CMAKE_AUTOUIC ON) was enabled before add_executable()
cmake_minimum_required(VERSION 3.5)
I was using qt6
I've downloaded a C++ project which uses Boost. It's rather complicated and plenty of files reference its parts, like:
#include <boost/graph/fruchterman_reingold.hpp>
I've put Boost directory in the project folder and added INCLUDEPATH += "C:/Programming/my-project" in the .pro file but for some reason Qt keeps telling me "No such file or directory" about every single file. Now note that if I change the paths to absolute the references start working. I've ran Qmake explicitly but still get the same problem. What can I do about it besides changing all paths to absolute?
I'm running Qt Creator 3.3.0, Qt 5.4.0, the compiler is MinGW 4.9.1.
So I've figured it out. Apparently the project had several projects inside but I wasn't aware that I had to change .pro files in every single one to tell the compiler to add a new path. After I did it the problem was solved. Thank you for your time, people.
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.
I compiled a library using the MinGW toolchain provided with Qt 5.0.2 on Windows. As a result I received a library.so file. First I failed using the library in a Qt application, but now I found out that everything works fine when I make a copy of the liblibrary.so file and call it liblibrary.dll or liblibrary.lib (which is the only file ending supported by the add library wizard in QtCreator).
Now I wonder if this is normal or if I should change something in order not to have both files (which are exact copies). Leaving one away makes the application crash during start up. I added the library as follows to my Qt pro file:
LIBS += -L"../path/to/library" -llibrary
INCLUDEPATH += $$quote(../path/to/library)
EDIT: I compiled the library using the MinGW of Qt, not as Qt project but using mingw32-make and the provided Makefile. As a result I get the liblibrary.so.
EDIT: It seems to work also when renaming the copy to liblibrary.dll instead of .lib. But still, I need two files to make the application work -- the .so and the .dll.
Chris
That's weird, I think you should get a *.a and *.dll files when building a shared lib with MinGW on Windows, as said in the documentation:
In windows, MinGW will output .a and .dll, MSVC2010 will ouput .lib and .dll. In linux, MinGW will output .so, .so.1, .so.1.0 and .so.1.0.0 – .lib, .a and .so are import libraries.
You definitely shouldn't rename your file!
Be careful to:
not to include the "lib" prefix after "-l" in your project file.
put everything after after "-l" in lower case as you're on Windows
not adding any extension to your library name after "-l"
add and reference the .h file used in your library
A real example using QtWebsocket lib:
INCLUDEPATH += "$${PWD}/include/"
LIBS += -L"$${PWD}/libs/" -lqtwebsocket
...
HEADERS += ... \
$${PWD}/include/QWsSocket.h \
...
In my include/ folder, I have the following file:
QWsSocket.h (taken from original project - required)
In my libs/ folder, I have the following file:
libQtWebsocket.a
QtWebsocket.dll
Edit: I struggled with this too initially. Have you tried to build your lib as a static lib instead (CONFIG += staticlib in your library project)? This might help you getting you *.pro file right before switching to using the shared library.
Edit 2: Ok, the fact that you get a *.so file is still a bit odd. In this question
the user has the same issue as you and keep both files, which is just a workaround. According to a later answer it seems that you need to modify your makefile to generate a file with the proper extension. Maybe this will help: http://www.mingw.org/wiki/sampleDLL
When trying to work in QtCreator, there is a problem with code completion for Qt libs. QtCreator says that it can't find Qt headers, so no code completion for them. I.e. if I write #include <QPainter> or #include <QtGui/QPainter> this line gets underlined with message No such file or directory.
But nevertheless compilation process works flawlessly. So, qmake finds everything correctly and the problem is in the QtCreator. Also, code completion works normally for all own files (created for project).
We've tried numerous fixes including reinstalling Qt twice, trying to mangle with qt.conf in QtCreator's dir, tried to find qmake.cache, searching the registry and googled a lot. We're using QtSdk 1.1 with bundled QtCreator 2.2.1 under Windows Vista, installed in the default location.
There is dirty solution to write path in .pro file, but we don't want to use it.
Choose one of the following files
Qt_install/mkspecs/common/your_os.conf
or
Qt_install/mkspecs/common/your_compiler.conf
By Qt_install I mean the directory where Qt is installed (not qt creator), e.g. C:\Qt\Qt 4.7.4\ and your_compiler should be mingw I guess (don't have a windows install).
In the .conf file, add the line with the path you added in your .pro, something like:
INCLUDEPATH += path1 path2 ...
The mkspecs files are implicitly included in all your .pro so code completion will work in all your projects.