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

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.

Related

Changing path in JVM options Launch4j isn't working

for some reason when i use the full path for the sdk lib the application runs..
--module-path="D:\tools\javafx-sdk-18.0.1\lib" --add-modules=javafx.controls,javafx.fxml,javafx.media
but since i want the application to run on other computers, i copied the lib file which contains javafx.media...etc to the application folder and tried to put the path to it as "lib"..
since it's in the same folder of the exe. but it didn't work..
i tried then to put the full path for the lib which is in the application folder and still it didn't work even tho I provided the whole path..
but when I reput the path "D:\tools\javafx-sdk-18.0.1\lib" it works again..
it feels like my application don't love other paths, he only works with this :(
what should i do ?
I've had much success compiling OS-specific, self-contained runnable programs using this JavaPackager library. It takes a lot of the 'grunt work' out of creating distributable programs from Java.
I solved this problem..
first i needed to copy the whole folder of javafx18.0..etc
not only the lib folder...2ndly when writting the path in Launch4j you must write it like this "../yoururl/" to make the path relative to the app folder...
3rdly i copied all my code and files to NetBeans in Maven project and build it using jlink...i created the runnable jar using eclipse and i converted the jar to exe then put it in the output folder of jlink build including the javafx18..etc
and it worked fine now my app works on all computers...thanks to Slaw who commented. i figured jlink by his help.

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

Qt with Visual Studio - cannot compile moved project

I have a project on Visual Studio 2010, which uses integration with Qt 4.8, some of boost features and all this stuff is versioned with SVN.
Everything was fine: I moved solution folder from one place to another, compiled it on different computers.
But once I've renamed solution folder, and when I tried to build the project - compiler wrote only one error:
Error 1 error MSB6006: "cmd.exe" exited with code 1. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets 151
But when I return old solution folder's name - everything builds without any errors again!
As i figured, compiler cannot use custom build steps for *.ui files and stops whole build process.
Probably, there is some issue with absolute pathing, but I cannot find it second day :(
As it often happens, the answer was hiding right on the ground.
While observing build output I got lines like this:
1> Uic'ing frmserver.ui...
1> File 'C:\Users\Theurgist\Desktop\JamServer (?????)\JamServer\frmserver.ui' is not valid
This issue was all because Qt compiler tools can't work with unicode-containing paths correctly (at least up to version 4.8)
There must be some references to the old folder location in either your .sln file or your .vcxproj file(s).
You should be able to fix this by:
Closing Visual Studio
Opening your .sln file and all the .vcproj files it loads in a text editor of your choice
Doing a search-and-replace for the old folder name, changing it to the new folder name.

Qmake does not support build directories below the source directory

I have created an application that compiles and runs like a charm on OS-X. I would now like to start getting it to work on Windows. To start, I copied the project to a windows machine and just tried to compile, but got this error:
:: warning: Qmake does not support build directories below the source directory.
Any ideas?
Set the shadow build directory to some folder on the same level of your project directory:
folder/
project/
project-shadow-build-release/
project-shadow-build-debug/
You can do this in the "Projects" view, via the toolbar on the left. To me, this warning was just an annoyance, a project never failed to build because of it.
Don't copy your project.pro.user file when you are copying a project from one machine to another, or from one directory to another. When you open the project, Qt Creator will offer to create a new build directory in the proper place.
Andref gave the correct answer to resolve this warning, but you may want to understand why this requirement exists.
In fact, the build directory must be at the same folder level as the project (i.e. it can't be above or below). The reason why is that the linker is called from the build directory. Hence, any relative paths to library files will be different than what you entered in your project file.
It kinda sucks. I like to put all intermediate files in their own folder. But you simply can't with qmake.
.pro.user are generated files by Qt Creator. They are unrelated to qmake and should not be touched (and not put into a VCS for that matter)
Just remove the files with the pro.user extension , worked for me
I also got this, trying to compile a project created on linux.
Another way to solve it is to change the paths in the .pro.user file (in the directory of your project)
Right Click on a project: Set As Active Project
Click on the Projects button (The one with the spanner image)
Edit build configuration : Debug / Profile / Release / and change the default directories, OR just uncheck the Shadow build check box.
The Build directory path should now change to black, from red

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