QtCreator (2.8.0), using shared libraries - qt

I developing a GUI app with Qt 5.1 and QtCreator 2.8.0 and I'm using a shared library (also compiled with Qt 5.1).
This is what I'm using in the .pro file:
INCLUDEPATH += ../MyLib
QMAKE_LIBDIR += ../MyLib/build/release
LIBS += -lMyLib
Regarding the "Run Configuration" (QtCreator) and under Linux (Ubuntu 12.04) I set the LD_LIBRARY_PATH to "(...)/MyLib/build/release" and it works well. However, on Windows, appending the library path (.dll) to PATH doesn't work. I don't get any compiling nor linking errors but when I run the app it immediately exits. If I put the .dll on the same folder as the executable it runs without any problem. Am I missing something?

Hard to say from the information you gave. Surely Windows does find the dll if you put its path into PATH. But maybe your dll uses another dll, which is not in the normal search path?
You might want to try the dependency walker: http://www.dependencywalker.com/
If your dll is based on Qt it might be that it does not find necessary qt plugins.
Check this out: http://qt-project.org/doc/qt-4.8/deployment-windows.html#application-dependencies
Qt 4, but Qt 5 is the same in this regard.

Related

Run .EXE without Qt

[ Solution ]
I want to run my app created with QtSDK on a machine that does not have Qt installed.
I tried to copy the DLL's from the BIN folder to the release of my project, but it did not work.
I tried the following:
I copy all dll's folder d:\Qt\Qt5.0.1\5.0.1\mingw47_32\bin
And pasted it in the folder of my project: d:\projects\mybrowser\mybrowser-build-Desktop_Qt_5_0_1_MinGW_32bit-Release\release
and send it to another computer without Qt
In computer without Qt, I installed vcredist_sp1_x86.exe and tried to run my application browsertest.exe
The following error occurred:
microsoft visual c++ runtime library: this application has requested
the runtime to terminate it in an unusual way
Q: What I really want to know:
How do I run an application built in Qt on other computers (Windows) without Qt installed?
Details:
Qt5.0.1 32bit
mingw 4.7 32bit
QtCreator 2.6.2
Windows 7 64bit.
Intel i5
Folders:
D:\Qt\Qt5.0.1\5.0.1\mingw47_32
D:\Qt\Qt5.0.1\Tools\MinGW
Qt/Mingw:
D:\Qt\Qt5.0.1\5.0.1\mingw47_32\bin\qmake.exe
d:\Qt\Qt5.0.1\Tools\MinGW\bin\gcc.exe
File .pro:
QT += webkitwidgets network core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = browsertest
TEMPLATE = app
RC_FILE = browser.rc
SOURCES += main.cpp\
mybrowser.cpp
HEADERS += mybrowser.h
FORMS += mybrowser.ui
If any information you missed, please let me know.
grateful
To distribute your application you need to copy the DLLs (only the DLLs necessary).
Copy the DLLs necessary from
<DRIVE>:\Qt\Qt<Version_qt>\<Version_qt>\mingw<Version_mingw>\ or <DRIVE>:\Qt\Qt<Version_qt>\<Version_qt>\mingw<Version_mingw>\bin\
eg.: C:\Qt\Qt5.2.0\5.2.0\mingw48_32\ or C:\Qt\Qt5.2.0\5.2.0\mingw48_32\bin
Paste the folder of your application.
Then copy the folders inside of <DRIVE>:\Qt\Qt<Version_qt>\<Version_qt>\mingw<Version_mingw>\plugins
eg.: C:\Qt\Qt5.2.0\5.2.0\mingw48_32\plugins
Paste the folders of your application.
Note: In this example (below), it was necessary to copy DLLs from different places and remove the Debug DLLs (used only to compile in Debug).
Note that the debug dlls end with "d.dll", for example: Qt5Core.dll and Qt5Cored.dll or Qt5Concurrent.dll and Qt5Concurrentd.dll, the ending with "d.dll" should not be copied.
The structure should look something like this (example):
c:\project\app.exe (your app created in Qt)
c:\project\Qt5Core.dll (dll from qt/mingw folder or qt/mingw/bin)
c:\project\platforms (folder from qt/mingw/plugins folder)
c:\project\platforms\qminimal.dll (dll from qt/mingw/plugins/platforms folder)
Only some DLLs the mingw will be needed, so I recommend using the Dependency Walker 2.2
The result should look like this (not all dlls are needed, this can vary by project type):
Thanks to:
+1 for #MartinBeckett, showed me the program to find the DLLs required.
+1 for #WouterHuysentruit, thanks to the application I indicated, I discovered that the contents of the mingw\plugins folder should go straight into the application folder.
#WouterHuysentruit I would consider your answer as correct, but you just said, so I put a simpler explanation. Thanks anyway.
"microsoft visual c++ runtime library: this application has requested the runtime to terminate it in an unusual way"
That's either an ordinary bug, or sometimes a mix of incompatible dlls
Use the (free) depends program on your exe to check which dlls it actually uses - it probably isn't linking all of Qt
Some Qt libs are loaded at runtime from a plugins folder, mostly image formats and database connections - but they woudln't give this error
windeployqt (delivered with QT 5.2+) should do (most?) of the work

Configuring Qt creator for KDE applications

I want to build some KDE applications. Here's what I did so far:
sudo apt-get install kde-full
add LIBS += -lkdeui in the .pro file of a project which used KDE libraries.
I am using the QtCreator and the above mentioned steps don't seem to be enough. Error message: KApplication: no such file or directory.
What are the steps to configure my system for KDE application development?
The recommended way to build a KDE project is use CMake, not QMake. I really recommend you this approach because some KDE applications, like plasmoids, can not be build correctly using QMake.
In addition you can use KDevelop, but if you prefer Qt Creator, you can use it with a CMake project without problems.
http://techbase.kde.org/Development/Tutorials/CMake
KApplication.h is typically located in /usr/include/KDE folder. Make sure you have it in your include path (i.e. INCLUDEPATH += /usr/include/KDE).

QtCreator: static library but still asking for DLL

I'm using QtCreator and I got two projects, each with an own PRO file.
The Viewer is a normal Qt app.
The other one, let's call it Utilities, is supposed to be a static library which is used in the Viewer.
However when I compile and run the Viewer (everything compiles fine), I get an error message telling me Utilities.dll was not found.
This is the first part of the PRO-file for Utilities:
QT -= core gui
TARGET = Utilities
TEMPLATE = lib
CONFIG += staticlib warn_on $$(QMAKESPEC)
Shouldn't it work that way?
Why is it compiling the Utilities.a file fine but asking me for the DLL at runtime? It's supposed to be a static library :(
Since I did not specify some needed libraries in Utilities.pro, it apparently did not link as you'd expect for a static library.
My platform is W7-x64, latest Qt SDK and MingW 4.4 bundled with it.
Hope anyone can help :/
Thanks!
The CONFIG += staticlib request your target library to be a static lib not the entire dependency chain ... I am pretty sure your .a lib will require mingw dlls to run ...
If you want to reduce dependencies try the MSVC tool chain (Qt provide pre-compiled package for that) you will end with one or two mandatory dll dependencies. Or you can link again static mingw SDK (you will probably have to build it your-self ...).

Developing Qt applications in Unix systems using Qt Creator

I'm developing a Qt application in Linux using Qt Creator (2.1 RC). I've created 2 projects, and used the wizard to add the library project to the application project. However when I run it, I receive the error:
/home/jakepetroules/silverlock/silverlock-build-desktop/desktop/silverlock: error while loading shared libraries: libsilverlocklib.so.1: cannot open shared object file: No such file or directory
Is there some qmake variable I can set so that Qt Creator will set up the environment properly to run? It's quite annoying to have to copy all the files to another directory with a launcher script just to be able to test the build. On Windows it works perfectly - Qt Creator automatically adds the directories containing the DLLs to the PATH when it runs your application (where running it from Explorer would say DLL not found). Mac OS X is even worse, having to run install_name_tool on everything...
So how can I set up my qmake files so everything works right from the run button in Qt Creator? Kind of hard to debug without this ability, too.
I've had a similar problem running qt apps with QTCreator on my linux machine. I've solved it by adding following lines to the .pro file of the client application:
unix:LIBS += -L/home/projects/my_libs/ -lmy_lib
unix:{
QMAKE_LFLAGS += -Wl,--rpath=/home/projects/my_libs/
QMAKE_LFLAGS_RPATH=
}
info on rpath is here: rpath
hope this helps, regards
Yes, Creator has a section where you can set whatever environment you need for running your app.
On Creator 2.0.0 this is accessed by: Projects -> Targets -> (your target) -> Run -> Run Environment (after you have opened your project)
You can then add or remove any environment variables you'd like, including LD_LIBRARY_PATH One thing I'm not sure of is if it is possible to substitute e.g. the build path into the value of those variables, so that you don't have to hardcode that into your LD_LIBRARY_PATH.
Another option would be to add a small shell script to your source tree which sets whatever variables are necessary, and add a "Custom executable" run configuration to run that script. That's accessed through the same screen.
Just using this:
unix:LIBS += -L/home/projects/my_libs/ -lmy_lib
unix:{
QMAKE_LFLAGS += -Wl,--rpath=/home/projects/my_libs/
}
It's sloved my problem too.

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