Applications works while debugging, but doesn't work when "released" - qt

So, I just made a standard, QtQuick 2 application, it has the default Recangle, Text and MouseArea. So, I just tried to compile the application in release mode, to see what files it would generate, and then I tried opening the application and this happened:
When I resize it, I cans see white space:
However it all works fine in debugging:
I am using Qt 5.0.1 and QtQuick2
Update
So, after running it through Dependency Walker it appears like there are three files missing: qt5quick.dll, qt5gui.dll, and qt5core.dll. Do I have to manually add them from somewhere?
The current directory structure is:
`test-build-Desktop_Qt_5_0_1_MSVC2010_32bit-Release/release
|+qml
|+test
|-main.qml
|-main.obj
|-moc_qtquick2applicationviewer.cpp
|-moc_qtquick2applicationviewer.obj
|-qtquick2applicationviewer.obj
|-test.exe
|-test.exe.embed.manifest
Note: I pasted the qml directory as suggested in Nemanja Boric's answer from the parent directory, but that didn't solve the problem! :(
Also, I was under the impression that none of the source (apart from JavaScript maybe) wouldn't be openly distributed with the app, but compiled or packed inside the application somehow (note the .cpp file and the qml directory)?
Update 2
The application works just fine when run from inside Qt 5 Creator:
Starting [...]\test-build-Desktop_Qt_5_0_1_MSVC2010_32bit-Release\release\test.exe...
QOpenGLShader::link: "(41,18): warning X3206: implicit truncation of vector type
"
[...]\test-build-Desktop_Qt_5_0_1_MSVC2010_32bit-Release\release\test.exe exited with code 0
Well, apart from that one awkward warning...

You need to copy qml files into your current directory. When you create release application with QtCreator, you will have this directory structure (or something like this):
example-build-Desktop_Qt_5_0_1_MSVC2010_32bit-Release
|- debug
|- qml
|- release // application executable is here
What you need to do is to copy qml folder to be in the same directory with your executable release file (simply copy qml folder into release folder).
About dll files - you can copy them manually from QtInstallDir/bin folder or you can add that directory into PATH, if you are developing on that machine - it could be easier.
You don't need to publish cpp files, but you need to publish qml files. What you can do, through I never succeed, but it seems to be possible is to bundle qml files into Resource file, and to load it from resources, but that can be extracted easily, too - so - don't put your logic or confidential informations in qml files.
Also, you need to copy all required dll files into directory with exe: qt5quick.dll, qt5gui.dll, qt5core.dll and libEGL.dll.

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

windeployqt does not work on projects that use qmldir modules

I am trying to deploy an application using the windeployqt --qmldir method. When the command is run from within the folder that contains the executable, all the dependencies are copied and everything appears to go well. Except, when I click on the application file to run the it on a system that does not have Qt installed, it simply will not start. I get the busy mouse pointer for a few seconds and then nothing. No errors or anything. It does start fine on the machine with Qt installed but not on the other. I tried deploying a few of my other projects using the same method and they all worked just fine. Then it occurred to me that it might be the multiple qmldir "modules" that I'm using. So I took a project that previously deployed just fine, added a qmldir module to it and deployed it again, aaaand nothing. Same "not starting" problem. How do I use the windeployqt tool with projects that have multiple qmldir modules? What am I missing? I am using a number of qmldir files, all of which exist within a single qrc resource file that houses all of my application's qml. Here is my project structure and the commands I tried:
-Top_Level_Project_Dir
-GUI_Construction
-fonts
-images
-javascript
-qml
-Construction_QML
-QML_Elements_Directory_1
- a bunch of qml files, some in their own folders
- qmldir
-QML_Elements_Directory_2
- a bunch of qml files, some in their own folders
- qmldir
-Singletons
- Globals
- qmldir
- Menus
- qmldir
-qml.qrc
- GUI Tests
The windeployqt commands that I have tried are:
windeployqt --qmldir C:\QtProjects\Top_Level_Project_Dir\GUI_Construction\qml <location of exe>
That does not work. Also tried:
windeployqt --qmldir C:\QT\5.15.1\msvc2019_64\qml <location of exe>
This made the deploy directory quite large because it copied everything but it still didn't work. Then I tried plugging in the import paths (specified in the main.cpp file using engine.addImportPath()) after the --qmlimport option:
windeployqt --qmldir C:\QtProjects\Top_Level_Project_Dir\GUI_Construction\qml --qmlimport C:\QtProjects\Top_Level_Project_Dir\GUI_Construction\qml\Construction_QML (same for each qmldir) <location of exe>
This also did not work. It just copied all my qml files to the deploy directory, which is something I want to avoid anyway.

Qt Creator could not find the executable, please specify one

I'm trying to run the texteditor.pro file in the QtSDK\Examples\4.7\tutorials\gettingStarted\gsQml directory with Qt Creator. When I try to build the project I get a window that says
Could Not find the executable, please specify one
with three fields to load files. Snapshot of the dialog box.
I'm running windows 7 64bit, with Qt Creator 2.4.1
I've solved the problem it was a missing dll file, but the executable didn't ask for it, so I put all the dlls from Qtcreator -> bin in the same folder with the *.exe file, then I deleted file after another until I figured out what files are required.
* It is a brute force way, but It did the job.
* Here is the file that were missing (libEGL.dll)
This project is not created in the normal 'Qt-executable' kind format. Rather its a 'plugin' kind project. So you cant run it directly like other projects.
[If you will open the project files you wont find a main() function!, which is supposed to be the entrance point usually for a C++ Application. All you have are a couple C++ classes. Take that as a hint]
About this example they have given the complete details here. And I quote:
We need to compile the file dialog C++ plugin before the text editor
can run. To compile, enter the gsQml directory, then run qmake and
compile using make or nmake, depending on your platform. To run,
launch qmlviewer and open the texteditor.qml file.
Else:
You create your own project.
Add these class files and the respective qml files to this project.
Add a main and create the respective objects required.
Make an application viewer and give "texteditor.qml" path as its source.
I had the could not find executable window pop up in my face in Ubuntu 12.10.
Here's how I got the "error":
Created a folder named Project;
Inside it, I ran "qmake -project" and then "qmake";
Created a main.cpp file inside the folder;
Opened the Project.pro file with Qt Creator and added the line "SOURCES += main.cpp" to it;
Pressed Ctrl + R to build and run the project.
Later on I deleted the folder and created it again, but this time creating a main.cpp file before trying to run any commands. I opened the .pro file with Qt Creator, created a main function in the main.cpp file, and pressed Ctrl + R, and it built and ran!

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

Eclipse CDT static resources under build folder

I'm building a C++ project under Eclipse and my release folder should include a static sub-folder with some files inside it, those are required by executable during runtime. The problem is that this folder is automatically deleted before every build - entire release folder is completely wiped out and I'm losing all the files inside it.
Solution is simple - need to place rm.exe from mingw utilites on path and Eclipse will delete only specific build files instead of removing entire release folder.

Resources