I have a Qt 5.5 dynamically linked installed with MingW 4.9.2 32-bit and Qt Creator 3.4.2. In my build tree I created a helper console non-Qt app that has literally 20 lines of code and does not rely on Qt (only uses qmake so I do not have to install cmake). I would like that app to be built statically but no option I set in the build make arguments seems to be accepted (static, static-libgcc etc.). Is it even possible or do I have to build it separately outside of Qt(Creator) and possibly get cmake instead of qmake?
If you wish to link the executable statically to the C++ runtime, then the static_runtime feature does it. You'll also want not to link with Qt:
# .pro file
CONFIG -= qt
CONFIG += static_runtime
The static_runtime.prf file is only available in Qt 5/6. It's not present in Qt 4. For Qt 4, you have to do it manually:
QMAKE_LFAGS += -static
Related
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.
I've read a lot of "duplicate" posts on the subject of statically linking your Qt project on windows to statically built Qt core libs. However, I was left very confused when I compared it to what I am seeing. What I gathered from all the posts is if you already have the statically built Qt libs (which I seem to have here C:\Qt\5.4\mingw491_32\lib) all you need to do is to include a line like so
LIBS += -LC:/Qt/5.4/mingw491_32/lib -lQt5Core -lQtGui
in your .pro file without having to specify -static anywhere. However, this line seems to do exactly ZERO. When I comment it out my project builds exactly the same way without it. The exe is the same size and when I try to run it from command prompt a runtime error appears in a dialog box saying it can't find Qt5Core.dll. Its clearly still linking dynamically. What am I doing wrong? Here is the whole .pro file.
#QT +=
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = testproj
TEMPLATE = app
SOURCES += main.cpp mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
QMAKE_CXXFLAGS +=-std=c++11
#LIBS += -LC:/Qt/5.4/mingw491_32/lib -lQt5Core
I clearly have major holes in my understanding of how Qt linking works on windows. Any help on this topic is highly appreciated.
Qt does not distribute static builds.
It seems you only have a dynamic build and got confused by the .lib/.a files. On Windows, there are 3 types of library:
Dynamic libraries (.dll)
Static libraries (.a or .lib depending on the toolchain)
Import libraries (.a or .lib depending on the toolchain)
Import libraries are only used with dynamic libraries. The import libraries are used by the linker when generating the exe, while the dynamic libraries are used at run time.
So if you have Qt5Core.lib or Qt5Core.a does not mean you have a static build of Qt.
To build your own static version of Qt, I suggest your read Building a static Qt for Windows using MinGW on Qt's wiki.
The major hint is: no matter how Qt is built, you shouldn't need to change anything in the project that uses Qt. Qmake and the configuration files in a given Qt install govern how the applications that use Qt are linked against Qt.
Another hint: a given Qt installation can be either configured for static or dynamic linking, not both. Thus any sort of configuration on the project end is superfluous: a given Qt install already "knows" how to link Qt correctly.
Any given .pro file should work whether Qt is linked statically or dynamically. You should not have any static-linking-specific entries. Remove the LIBS line from the project.
If your executable is dynamically linked, the only reason is that you're using a dynamically linked build of Qt. You should make a static build yourself first, and then use it with your project, and your executable will be statically linked against Qt. It's that simple.
Qt Creator doesn't care about these details either. All it does is invoke qmake and then the make tool. But each qmake is specific to a particular installation of Qt, and that qmake is configured to access that installation's configuration files, and those files contain the data needed to select the proper linking etc. So all of the information is specific to a particular kit one is using, and specifically to the Qt "version" that kit is using (really, a Qt installation because there can be multiple installs of the same version, configured differently).
How am I supposed to use my static build of Qt in my project directory? There seems to be a missing step in the official documentation between building a static version of Qt and then building a statically-linked version of your app with that static version of Qt.
There's no explicit step, since all you need to do is use that statically-compiled Qt to build your project. That's all. From the command line, simply invoke the statically-compiled Qt's qmake and your project will statically link to Qt. From Qt Creator, add the statically-compiled Qt's kit to your project's configurations and build for it.
Of course you must first add that Qt version to Qt Creator, and add it to a new kit. Note that as far as both Qt and Qt Creator is concerned, a "Qt version" is a synonym for a build of Qt. So if you have 4 different builds of Qt 5.3.1 (say dynamic multithreaded, dynamic single threaded, static multithreaded, and static), they are considered different Qt versions. Because a "Qt version", as used throughout, has nothing whatsoever to do with the sources of Qt, just with a build of Qt. If all you do is download a source package of Qt, you have no Qt versions yet :)
I downloaded qt recently.
I want to create an standalone exe,
but I don't know what can I do.
In Qt5.2, the folder "(Qt)\lib" is exists, but i can't use it in Qt Creator.
So, should I build from source,
or configure Qt Creator and use the "lib***.a"?
Any ideas?
Environment: MinGW-32 4.8.1(TDM) / Windows 7
You seem to have tried CONFIG+=static, but that is not meant for this use case. That is used when you would like to use build your library to be static after the end of the build.
This is not the case here because you already have static Qt libraries available, so what you wish instead, to link those statically against your executable.
You would need to use this in your qmake project file:
LIBS += -L/path/to/the/static/QtCore -lQtCore
You could also use, albeit this would make the build-system less portable across different platforms:
LIBS += /path/to/the/statis/QtCore/libQtCore.a
I've heard that it is possible to build non-Qt applications (like simple C++ HelloWorld) with Qt Creator. I downloaded and installed Qt Creator, and tried to compile simple code with it. But I didn't succeed: Creator needs qmake to create makefile.
Although the package I downloaded includes MinGW, there is no qmake inside of it.
I still want to use it just like an IDE to create simple C++ sources and compile them with MinGW. Is it possible to use Qt Creator without installing whole platform?
Qt Creator support CMake projects, you just need to choose Open a file or project and select the root CMakeList.txt of your project.
If you want to define your own build workflow, you can remove the default build step and create your own custom build steps (Qt Creator Build Steps).
I think you can modify the build step to remove qmake and use your custom make file.
You totally can!
You can write a .pro file yourself and use it as a project file to use QtCreator without linking / using any of the Qt libraries.
In Project / Compilation Parameters, you can actually tune the compilation steps (removing the qmake step and adding your own).
I use it for a big project of mine and it's very efficient: QtCreator's C analyzer is diamond.
Here's a sample project file for me:
TEMPLATE = app
TARGET =
DEPENDPATH += . include
INCLUDEPATH += . include
# Input
HEADERS += include/x.h \
include/y.h \
include/z.h
SOURCES += src/x.cpp
Note that I actually use qmake to generate this file automatically, but you can also put your hands into it and modify it by hand.
Afterwards, it's only a matter of $ qtcreator yourfile.pro.