Qt project with Boost - qt

I have a Qt project which requires boost. The project works fine in Linux, but compiling on windows has presented some difficulties. I have been able to make it work, but not properly, and that bothers me.
Here's the relevant part of .pro (working)
win32{
INCLUDEPATH +=C:\Boost\Boost
LIBS += "C:\Boost\Boost\stage\lib\libboost_system-mgw53-mt-1_65_1.a"
LIBS += -lws2_32
}
This does not work, but should according to the documentation I've found online.
win32{
INCLUDEPATH +=C:\Boost\Boost
LIBS += -LC:\Boost\Boost\stage\lib -lboost_system-mt
LIBS += -lws2_32
}
Note: Boost was compiled using the mingw distributed with Qt Creator.

I believe I have found the solution! I noticed that I had two copies of every boost library in \stage\lib.
libboost_system-mgw53-mt-1_65_1.a and libboost_system-mgw53-mt-d-1_65_1.a
I compiled the project using both and while the former had some warnings, the latter did not. Removing libboost_system-mgw53-mt-1_65_1.a from the folder allowed -lboost_system-mt to work just fine.
I don't know why I had both of these files, but it was undoubtedly due to me fumbling around with compiling boost.

Related

Qt Quick Designer Components module Static Linking not working

I'm trying to cross compile Qt Quick Designer Components to get QtQuick.Studio.Effects module on Qt 6.5 on arm64 target as I'm getting "module 'QtQuick.Studio.Effects' is not installed" when I try to to run my cross compiled qt application.
So far I have cross compiled Qt Quick Designer Components with help of this and it outputs libQuickStudioEffects.a static library. I tried to link it in .Pro file by adding the library with qt creator which generated following lines.
unix:!macx: LIBS += -L/home/user/qt/ -lQuickStudioEffects
INCLUDEPATH += /home/user/qt/
DEPENDPATH += /home/user/qt/
unix:!macx: PRE_TARGETDEPS += /home/user/qt/libQuickStudioEffects.a
lib file and executable both are in /home/user/qt/ location in target and host pc.
also I tried with following line.
LIBS += /home/user/qt/libQuickStudioEffects.a
So far executable is not detecting the lib file and giving me the above mentioned error. I can run other cross compiled qt6 programs on my target device without any issue. My host runs Ubuntu 20 and target runs on debian 11. Any help is really appreciated. Thanks.
Build the dev branch from here and it will give the dynamic QtQuick.Studio.Effects library which can be cross compiled.

How to add the librealsense2 to Qt creator?

I'm pretty new with OpenCV & Intel Realsense device. I don't know how to add the librealsense2 to Qt creator. I searched many ways but they are not working for me.
I have no idea how to make it. So anybody has any hint??
First of all be sure about that you properly installed librealsense. You can check here to install.
After installation is done, you should add INCLUDEPATH and LIBS to .pro file. You didn't tell which operating system you are using. If its ubuntu, you can add simply like:
INCLUDEPATH += /usr/include/librealsense2
LIBS += -L$$DESTDIR/ -lrealsense2

Qt4 change linker search order

I have a Qt project which compiles library and application which links with the library.
With Qt5 everything works just fine. But with Qt4 I have one annoying problem.
On linking the application qmake for some reason brings:
-L<where_qt_libs_installed>
before
-L<build_dir/library_dir> -lmylib.
So if Qt4 libs installed in /usr/lib and previous version of my library is there too, the application will link with old version of library what usually finishes with link failures.
Is there any way to change link order except adding
LIBS += <full_path_to/libmylib.so>
Finally I solved it with this.
LIBS += -lmylib
!greaterThan(QT_MAJOR_VERSION, 4):equals(QMAKE_LINK_SHLIB, g++)|equals(QMAKE_LINK_SHLIB, ld) {
QMAKE_LFLAGS += -L<build_dir/library_dir>
} else {
LIBS += -L<build_dir/library_dir>
}

Linking opencv ".a" libraries with mingw and Qt 5.0

This one is tough ! Please don't mistake this for a newbie question ;) I have far too many miles in this OpenCV + MinGW static stuff for the simple mistakes....
Environment:
a. Qt 5.0.1 built with MinGW (the standard opensource download from qt-project) - so everything is built with the same MinGW environment.
b. Using CMake I setup minimal build (using the same g++/gcc as Qt) and turned OFF SHARED_LIBRARIES.
c. generated the cmake + mingw32-make + mingw32-make install works fine.
up till here everything looks pretty smooth ...
Now when I added:
win32-g++:INCLUDEPATH += D:/Dev/opencv/build/install/include
win32-g++:LIBS += -LD:/Dev/opencv/build/install/lib
win32-g++:LIBS += -static
win32-g++:LIBS += -llibopencv_core243d
win32-g++:LIBS += -llibopencv_imgproc243d
win32-g++:LIBS += -llibopencv_highgui243d
(and also without the "win32-g++" addition..)
I get d:/dev/qt/qt5.0.1/tools/mingw/bin/../lib/gcc/i686-w64-mingw32/4.7.2/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -llibopencv_highgui243d
...
...
now.. I do have libopencv_highgui243d.a in the right directory, but the ld.exe linker is ignoring anything else than a lib ! which supposed to be a MS library (which I wanted to avoid in the first place!!!) - I even tried to rename the .a files to .lib which caused the linker to regard the files, but show many "unreferenced" errors...
So who's to blame? the linker? CMake? mingw? Qt? ....
I tried many command line / flag options but without success ..
You should be referring to the libraries as:
LIBS += -lopencv_core243d
LIBS += -lopencv_imgproc243d
LIBS += -lopencv_highgui243d
Since -l already inserts lib at the beginning of the name.

Libqxt under Qt Creator

I want to create a tiny app which needs global shortcuts. So, I have downloaded the current version of libqxt (0.5.1) and opened as a project in Qt Creator.
Libqxt compiles without problems in this way, so I thought that adding this in the tab Dependencies of my project it would get added automatically in the build, like Eclipse does with JAR libraries (I know that are different IDEs but it seems to be a common feature among them).
What happens? Qt Creator compiles qxt before my project, when needed, but when I want to include its headers Qt Creator keeps warning me that it cannot find them.
Probably I am missing the correct name of headers (I tried the headers showed in qxt documentation: http://doc.libqxt.org/0.5.0/classQxtGlobalShortcut.html)
By the way, I looked the code for global shortcuts and I think I can rip it out and use it in my app as is and I am going to credit qxt team and open the code of my app.
from the documentation
Add the following lines to your .pro file:
CONFIG += qxt
QXT += core gui
Note: While building the Qxt on Linux do not forget to do a sudo make install otherwise this little piece of magic may fail to work.
Qt Creator doesn't know how to expose different libraries to your projects. It's developer's duty. Dependency ensures only that mentioned projects are already built before building your main project.
Your real concern was using Qxt without proper installation. Assuming that configure have been run and libqxt have been built (using Qt Creator or manually via qmake+make), my solution is adding following snippet (with obvious QXT_DIR customization) to .pro file:
QXT_DIR = $${IN_PWD}/../libqxt-0.5.1
LIBS += -L$${QXT_DIR}/deploy/libs
INCLUDEPATH += $${QXT_DIR}/deploy/include
for(module, QXT) {
MODNAME = $$upper($$replace(module, "(.).*", "\1"))$$replace(module, "^.", "")
INCLUDEPATH += $${QXT_DIR}/deploy/include/Qxt$${MODNAME}
INCLUDEPATH += $${QXT_DIR}/src/$${module}
win32:CONFIG(debug, debug|release):MODNAME = $$join(MODNAME,,,d)
LIBS += -lQxt$${MODNAME}
}
Unfortunately I'm not sure whether it works in complex projects.
By default Qxt is built in release mode, but Qt Creator uses debug mode and it leads to broken binaries of projects depending on Qxt under Windows. You have to switch your project to release mode or build Qxt in debug mode (run configure -debug and rebuild Qxt).
Last thing: In Windows you won't be able to run your project from Qt Creator even if you successfully build it. You must copy needed Qwt*.dll files (use the d-suffix versions if you're in debug mode) from libqxt-0.5.1/deploy/libs to your_project/(release|debug) directory .

Resources