mt.exe in Qt StandAlone .exe - qt

I finally built a static version of Qt 5.1.1 using microsoft visual studio. I created my .exe standalone file using this code:
qmake Hello.pro
nmake release
cd release
mt.exe -manifest Hello.exe.manifest -outputresource: Hello.exe;1
what is mt.exe and what does the last line do with the "Hello.exe" file?

You could just use CONFIG += embed_manifest_exe though, but in essence you need to put the manifest file beside your executable and the last line seems to take care of that.
That is, it is adding a manifest to your "Hello.exe" executable file.
If you do not happen to know what manifest files are, then you can read the MSDN documentation below, but in short: they are carrying run time information for your executable in this particular case:
http://msdn.microsoft.com/en-us/library/aa374191(v=vs.85).aspx

Related

Qt6 qt_generate_deploy_app_script plugin DLL copying

Currently I have to manually copy the platforms and imageformats plugin folders to the directory containing the .exe that MSVC compiled. This is very tedious as the output folders often get deleted if you're working on your CMakeLists.txt or changing compilation target.
Now qt_generate_deploy_app_script seems like an official Qt solution to solve this problem, but it does not work.
I have added the CMake bits to my CMakeLists.txt as stated
qt_generate_deploy_app_script(
TARGET HiveWE
FILENAME_VARIABLE deploy_script
NO_UNSUPPORTED_PLATFORM_ERROR
)
install(SCRIPT ${deploy_script})
I can see some generated deploy scripts appear under build\x64-RelWithDebInfo\.qt, but they do not seem to be run as no DLL folders get copied to where my .exe is.
Am I misinterpreting what qt_generate_deploy_app_script should do or is it simply broken?
If you want to Creat exe in windows From Qt project you should use windeployqt
To Deploy and create Exe output with QT in windows you should follow this way:
put your compiler path in your system path. for example, if you use mingw81_64, you should set it. something like Qt/tools/mingw81_64/bin
copy exe file that provides after building in release mode in one
folder and run mingw81_64 cmd (it has separate cmd) and cd to that
folder path
windeployqt app.exe
you are using Cmake So first create one release output and then use step 3.
This command will get all dll needs for your app and your exe will work .
if you use qml
windeployqt --qmldir (the path of its directory ) app.exe
and also see these youtube videos for more info:
https://www.youtube.com/watch?v=LdSTgR0xJco
https://www.youtube.com/watch?v=hCXAgB6y8eA

How to make setWindowIcon work properly in a stand-alone executable (Qt5.14 + VS2019)?

I am programming a Qt application in MS Visual Studio Community 2019. I am trying to add an icon to my application window with the following command, and I also have the corresponding file my_icon.ico mentioned in the .qrc file:
setWindowIcon(QIcon(":/my_icon.ico"));
When I build and run my program in VS, everything is perfect - the icon replaces the standard one. However, when I make a release and try to run the resulting stand-alone executable, the icon is NOT shown! This is particularly weird as images which I also mention in the .qrc file (pictures for buttons) are on their places.
I have tried to put my_icon.ico alongside the .exe file, but with no result.
I give up, please give me a clue what might be happening here.
Thanks to chehrlic, I understood that it was as simple as running the windeployqt.exe on the .exe file build by the Release configuration by Visual Studio.
This will link all required libraries dynamically.
Avoid using this tool while the .exe file is inside the Release folder as it will create many other files & folders near .exe file. I have copied my_app.exe to a fresh directory and ran the following command from it:
C:\Qt\5.14.1\msvc2017_64\bin\windeployqt.exe my_app.exe --release
See https://doc.qt.io/qt-5/windows-deployment.html for more details.

Qt Creator: how to embed custom manifest in .exe

I have a custom Manifest file and would like to embed it inside the executable. I use MS Visual Studio 2010 compiler and Qt 5.2.1.
I use Qt Creator as the IDE and CMake for making release builds.
What options should I set in .pro and CMake files?
I tried to pass '/MANIFEST...' like flags to the linker, but they seem to be unsupported by VS 2010 linker.
Eventually I've found the solution.
First it is necessary to add the following line to the .pro file:
CONFIG -= embed_manifest_exe
this will disable embedding of the default manifest file. After that it is necessary to add a windows resource file:
RC_FILE = app_resources.rc
.rc file is usually included to embed version information into .exe, but as soon as manifest is also a part of the executable resources we could reference a custom manifest file in it, just add the following line into app_resources.rc:
1 24 myapp.exe.manifest
where 1 is the resource ID, 24 is the resource type - RT_MANIFEST, and myapp.exe.manifest is the file with our custom manifest.
If you don't need version info then app_resources.rc may contain just this single line.
That's it.
For CMake the steps are as follows:
1) include app_resources.rc in the list of sources of the target
2) add the following line to disable embedding of a default manifest file:
set(CMAKE_EXE_LINKER_FLAGS "/MANIFEST:NO")
For some unknown for me reasons /MANIFEST:NO didn't work in .pro file. The linker failed with an unknown option error. However it works in CMake. The linker is the same from VS 2010...
Using below qmake script based manifest injection you do not need to include the manifest in any *.rc file (works for MakeFile based compile where qmake does generate the MakeFile)
QMAKE_MANIFEST = $$PWD/x86_user.manifest.xml
Note:
this works even if we have set the RC_FILE = Res.rc (i.e. since this takes action and injects the manifest to .exe after the compile is done)
you need to recompile to see effect...
I can't help you with the qmake side, but for CMake, you should be able to just list the manifest file as one of the sources of the target. This requires CMake 3.4 or later (see release notes).

Qt: mingw compiled library does only work with both library.so and library.lib file present

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

how to create .exe file for my Qt based app

i wrote a program in Qt-Creator 1.3.1 and Qt 4.6.2
and realy dont figure out how to create a simple .exe file for the program i just wrote...
i rather do it with the Qt-Creator if it's possible
In Qt Creator, when you build (Ctrl+B) your project, it always creates a .exe that is executed when you run the app from Qt Creator (Ctrl+R or the big play button).
If you want to find this .exe, you should look in the folder where your .pro (the project file) is located in the folder debug (or release depending on your build configuration).
#Live is right. See in release or debug dir. But if you move the .exe and want to execute you will get notofications about DLL's that miss. You can find them from yout Qt installation dir. Put next to your exe file all required DLL's and you're done! The DLL files will tell your your exe file while you execute it!

Resources