Qt C++ Stand alone executable in Windows - c++

I want to make my Qt C++ program a stand alone single application. By the way, I am using Qt creator 2.2.1 which is based on Qt 4.7.4. I followed the instructions from http://www.formortals.com/how-to-statically-link-qt-4/ to statically link the libraries. I did not know where to find the configure.exe in the QtSDK folder so I downloaded "qt-everywhere-opensource-src-4.7.3" and followed the instructions.
I was unsure in Step 4 because the windows Qt options do not look similar. Its not a path to a folder but rather a path to qmake location and I am not sure what to choose for that option.
If anyone knows how to create the program as a stand alone without needing any dlls and can help me out, I would really appreciate it.
Thanks

Regarding the step 4 you mentioned, in QtCreator you need to point the qmake executable you will find it in the build tree (where you built Qt statically) in the bin folder.
I guess if you have problems on step 4 you should have built the static version of Qt, you've done 95% of the work !
The moment QtCreator will accept the qmake you made, you will just have to select this version use any wizard to get you first app, then add CONFIG += static to you .pro file.
Here some Qt tutorial just in case.

Related

How to build custom widgets for qt designer

I've read through the tutorials of Qt, I've searched the net, but I can't find the exact way on how to build custom witgets with Qt 5.8.x. In example with this tutorial one is able to build widgets for Qt 4.x as I already succeeded. For Qt 5.8.x I'am lacking in such straightforward tutorials.
Even if you use the build in wizard of Qt for setting up such custom widgets projects, one will end up with none recognized widget libraries.
So first of all, there is a confusion with the installing path, that the makefile should mention while installing the plugin.
In the project file one can find the section
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target
After a straightforward installation of the open source mingw version of Qt 5.8.0 on a windows 7 machine in the path C:\Qt\Qt5.8.0, the variable "QT_INSTALL_PLUGINS" will extend to
C:\Qt\Qt5.8.0\5.8\mingw53_32\plugins
thus the "target.path" for the
make install
will be read as
C:\Qt\Qt5.8.0\5.8\mingw53_32\plugins\designer
But on the plain installation of Qt 5.8.0 with mingw the designer searches its plugins in
C:\Qt\Qt5.8.0\Tools\QtCreator\bin\plugins\designer\
As someone already suggested to me, one has to set the environment variable "QT_PLUGIN_PATH", where Qt Creator as well as Qt Designer ( in the subdirector "designer") searches its plugins in. So in order that Qt Creator still works properly one has to set the environment variable "QT_PLUGIN_PATH" to
the original path as well as to
the install path reffered to by $$[QT_INSTALL_PLUGINS]
So on my Windows 7 environment I set the variable "QT_PLUGIN_PATH" to
C:\Qt\Qt5.8.0\Tools\QtCreator\bin\plugins;C:\Qt\Qt5.8.0\5.8\mingw53_32\plugins
Afterwards Qt Designer is able to find the custom build widget library. But Qt Designer it not able to load the library. One interesting thing is that the designer also refuses the libraries provided by the installation of Qt itself.
on loading the custom widget lib it says:
"... .dll can't be loaded: the given procedure was not found"
on loading the libs supplied by the Qt distribution itselfs in the path C:\Qt\Qt5.8.0\5.8\mingw53_32\plugins\designer it says:
"... .dll cant be loaded: the mentioned modul was not found"
What I've done to build the library is, that I just ran through the project wizard to generate a custom widget for Qt Designer. With the so generated project I get the result of a non loadable lib, as mentioned above.
What do I have to change in the source/project files in order that the Qt Designer ist able to load the lib properly?
Thanks for any hints or suggestions!
You seem to use the MinGW compiler.
You cannot make plugins with that compiler with the default supplied Creator as it's compiled with Visual Studio 2013/2015 (depending on the Qt version).
Due to how DLLs works on Windows, you must use the same compiler that Creator is compiled with to build the plugin (otherwise it can't load it).
Go to "About Qt Creator" in the Help menu to check.
Also make sure to build the plugin in Release mode.

How to run qmake from the static Qt

For making a very simple Qt app "installable" on other systems, I'm using Qt Installer Framework following this link.
In bottom, in Setting up Qt Installer Framework, number 1 orders to have Qt Installer Framework source code. I downloaded it from here. (qt-installer-framework-opensource-2.0.1-src.zip)
Now I don't understand the next instruction there :(
It says:
2- Build the tools by running the "qmake" from the static Qt, followed by "make" or "nmake".
My question is, first what does it mean?
And from what path?
I don't know how to do it:(
qmake comes with the qt-framework and is a make file generator. (an alternative to cmake).
You call qmake on a .pro file from your project. This .pro file have to contain your source code files project dependencies and more.
Consider that you have a project folder with your source code and the .pro file. Then you call the qmake command in this folder. qmake is an program itself, which you can find in the bin folder of your qt-installation. If qmake is in your path variable, you go to the terminal, navigate to the specific folder and just write:
qmake
After that qmake will create a makefile. Then you could call makeand your program will be build.
I hope my answer helps you. You can learn more about qmake on the website of Qt. Here is also a very good qmake tutorial: klick
edit:
how to call make on windows:
download and install cygwin from
http://www.cygwin.com/setup-x86.exe - 32 bit installer or
http://www.cygwin.com/setup-x86_64.exe - 64 bit installer.
then start the Cygwin terminal (Cygwin.bat) and navigate to your folder and call
make
and that will build your qt-installer!

How to compile a Qt program without installing sdk

Can someone tell me if it's possible to compile a project that works with Qt but without installing the entire sdk ? I mean, something like recompile Qt source code and link the libraries or something like this.
I know my problem is weird but I work in special conditions : I am on a linux machine and I have to work on a windows project therefore I use a distant server on windows to compile but I can't install anything on this serveur. I need an idea to have a fully portable folder with Qt who can compile without installing anything.
I hope I was clear in my explications.
Thank you for your help.
I has combined comments in answer.
You need to install compiler (e.g minGW) and Qt Library (as needed version).
You should add into environment variable 'PATH' your path to qmake and compiler.
Start terminal and move to directory with your source code of Qt project.
Run qmake and then exec make (e.g. It, for minGW, is mingw32-make).
For your case, you may choosen 2 way:
Build static Qt Library from source code and use static linking with your project.
Install Qt Library and copy libraries near your project with dynamic linking (recomended).

To add or not to add Qt Libs and Headers to the Project Directory

Does it make sense to add relevant Qt Libs and headers (opensource version) to a projects repository or should I just reference them from the sdk directory ?
I (alone) am developing a cross-platform (windows/linux) c++ application which, will be using a number of thirdparty opensource libraries including Qt, OpenCV, log4cpp to name a few.
I started off development in Qt Creator for convenience (speedy GUI creation). Currently I have the Qt Sdk installed on both Linux and Windows outside the project directory.
I'm planning to move to CMAKE to for better configurability, e.g out-of-source builds and independance from Qt Creator and I would like to have all dependencies included in the project directory structure -so that I or anyone else can checkout the project and build without needing to install any other dependancies.
I have added all libs but Qt's to the directory as I am a little unsure weather its worth it -it seems like CMAKE depends on the Qt Sdk for compiling Qt specific files i.e moc, ui etc... (see here) is this the case ? or is there a better suited build tool ? (Originally I was I going to use Scons but I decided not to as the there seemed to be limited support.. and there hasn't been developement on Qt4 Tools since 2010, which doesnt inspire confidence either.)
Qt is too big to be put in a project directory, even if you include only one of its modules. Also you have some convenient functions in CMake to use Qt (add moc, rcc, ui). You can even write these functions by yourself (in fast, they just add a pre-build command).
For the build operations: you will need to use the moc (and maybe ui, rcc, ...), which is not provided by CMake. So, a person wanting to build your application must have the Qt SDK installed. Luckily, this installation is very easy.

Compiling a static QT application on Windows

I am new to QT and I am enjoying the experience except for the fact I cannot manage to statically link the QT library to the output binaries. When I run the output file outside of the QT directory, I get The program can't start beacuse QtCored4.dll is missing. Obviously QT is dynamically linking their libraries and requesting a .dll I do not have. Is there a way to statically compile QT's libraries into a static binary so none of QT's dlls are required? I ask this because I am already up to 11 .dlls for my project, and I would really like to cut down the amount of files that have to be distributed with my software. Size is not a problem for me. Thanks.
I have tried adding CONFIG += static to the .pro file, but to no avail.
First off, you can't statically link Qt unless you've bought a commercial license. To do so would put you in violation of the LGPL license under which the non-commercial version is distributed. I feel your pain, I've got many, many DLL's to go with my software.
Thankfully, you probably do have the DLL's if you used the installer: you don't need to build from source, that should have been done automatically. You'll find them in Qt\Version\bin, where Qt is the directory you installed Qt, and version is the version of Qt you installed. For example, mine is found in G:\Libraries\Qt\4.7.1\bin.
I did, however, have some issues with not having one of the DLL's built - one for working with OpenGL - and performed a rebuild to do so. I've also done so when I've switched versions of Visual Studio. I think it's handy to be able to do so, it's easy, Open a terminal in the Qt directory, and execute:
configure.exe -platform XXX'
Where XXX denotes the type of build you want to perform. Valid options include win32-msvc2005, win32-msvc2008, win32-msvc2010. So I use:
configure.exe -platform win32-msvc2010'
Other options are detailed here. These instructions apply if you've downloaded the source code, however you might have to add the current directory to the path variable like so:
set PATH=%cd%\bin;%PATH%
The whole procedure should take about an hour.
You need to download the source packet of QT and compile it. It takes some time but is not really complicated.
Download and unzip QT source
Start a compiler shell (Visual Studio or mingw)
Execute configure in the QT source directory - add a flag for static compile here
execute make (Visual Studio nmake)
Wait some hours depending on the speed of your machine