Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due
COMP282 – The C++ Programming Language
GUIDE TO Qt APPLICATION DEPLOYMENT
Document Version 1.1
For submission of your C++ / Qt programming assignment, we require two things:
The above two items need to be in a ZIP file, with two zip files inside:
source.zip for the source code files, and application.zip for the application package.
We will be using a Windows PC to test the application, so your solution should be packaged for Windows deployment. The easiest way to do this is to make sure your project runs from Qt Creator on a Windows PC, and follow the deployment steps (below) on that Windows machine.
Note: If you have not been able to use Qt, and have opted to submit a console-based application (you will lose marks for this but at least you will be able to submit a C++ application) then you should zip up the Visual Studio project folder, as was done for Assignment1. Make sure that source files are included.
The Windows deployment tool windeployqt automates creating a deployable folder with the necessary Qt dependencies (libraries, QML imports, plugins, and translations) to run an application. This folder forms an installation tree suitable for Windows desktopapplications, facilitating the packaging into an installer.
First lets establish where your QT directory is. Open a command window: hold down the windows key and tap R, then type cmd and click OK:On my laptop, I have a folder called QT on my c: drive and it looks like this:
You’ll see there is a folder called 6.3.1 (which is the version of Qt I am using – yours may differ). Inside that is:
And now you can see the mingw_64 folder. This is the compiler folder. My installation uses the MinGW_64 compiler (Minimalist GNU for Windows 64-bit). Yours will probably be the same although it is possible yours may use MSVC or Clang. Either way, the folder name in here is the last part of your Qt Directory (QTDIR).
So in my case, my QTDIR is C:\QT\6.3.1\mingw_64\Make a note of yours and navigate to it in the command window. (in my case I would type cd C:\QT\6.3.1\mingw_64\)
The deployment tool we need is called windeployqt and is in the QTDIR/bin/folder. so when in your QTDIR folder, type:
It then copies any identified dependencies to the directory of the executable. windeployqt modifies the hardcoded local paths in Qt6Core.dll to relative ones.
For Windows applications, essential compiler runtime files are also transferred to the deployable folder by default.
Further details on additional arguments can be found in the tool's help documentation. To see that, type windeployqt –help
[If this command doesn’t work, you may need to run the script QTDIR/bin/qtenv2.bat to set it up. ]
2. Packaging resource files (e.g. image files)
You may be using image files (e.g. the playing card images). The executable needs to know where to find them and you need to tell windeployqt to package them up. Your pathname for the images probably won’t work on another computer so we have to use relative pathnames and package the images folder in the correct place.
There are at least two ways to do this. I will describe both here.
If your project source code does not know the names of the image files in advance (e.g. it extracts all files ending in *.png from a folder like the Memory Card Game did), then you should use Method 1, which reproduces the images folder on the target system.
If your project source code knows the exact filename of all the images used and loads them individually using the exact filename (i.e. no wildcards) then use Method2.
Method 1 – manually including the image folder
Your project’s output folder will be generated by Qt Creator when you first build/run a project. So in my case, with the memory card game, my output folder is: build-example6-Desktop_Qt_6_3_1_MinGW_64_bit-Debug
If you want to find out what your project’s output folder is you can use this in your project
Here you can see I have copied my images folder into my project output folder.Once the images folder is in the output folder, you need to change the image filenames in the source code. E.g. in the memory card source code, this:
QDir directory(“C:/Users/andyrox/Documents/qt_examples/images/animal_images”); becomes this:
Check that this still works when you run the application from Qt Creator.
Now we come to packaging the application. For this we use windeployqt from the command line.
From the command line, go to your compiler’s binary folder.
in my case (and in most cases) this is:
(The version number 6.3.1 may be different on your system)
Then we run windeployqt. The syntax is: windeployqt <path_to_output_folder>
In my case I would type: windeployqt C:\Users\andyrox\Documents\qt_examples\build-example6-Desktop_Qt_6_3_1_MinGW_64_bit-Debug\debug
This will copy most of the required Qt dependencies into the project output folder.
So now my project output folder looks like this (you can see that there are extra folders and dll files):Now we need to make sure that required dlls from the compiler’s bin folder are included in the application. You need to copy these files (highlighted in grey):and put them in your output folder.
So now my output folder looks like this:
Now you should be able to zip up everything in the output folder to a zip file (call it application.zip).
You can test if it has worked by unzipping the folder on another machine and running the executable. If your game works, it’s been packaged and deployed correctly.
Method 2 – Using the Resource Collection File
There is a more sophisticated way to do it, which is to use a Resource Collection File (resources.qrc), which specifies all the images used by the project and packages them up.
Then you change the filenames for the images to redirect them through the QRC file by using a colon (:).
However this more sophisticated way only works if you are individually loading the images using their specified filenames. Here are the steps:
(1) You need to make a file called a Resource Collection File with the filename resources.qrcIn this file you need to list all the images you use in the project.
This is an example qrc file for the playing cards. Obviously my file paths will be different to yours, soyou will need to ‘search and replace’ my paths with yours, so that they are pointing to the files on your computer.
So in your source code, the files would now be loaded using something like this (your code may be different, the important thing is the pathnames):
(3) Then we run windeployqt. The syntax is:
windeployqt <path_to_output_folder>
windeployqt C:\Users\andyrox\Documents\qt_examples\build-example6-Desktop_Qt_6_3_1_MinGW_64_bit-Debug\debug
So now my project output folder looks like this (you can see that there are extra folders and dll files):Now we need to make sure that required dlls from the compiler’s bin folder are included in the application. You need to copy these files (highlighted in grey): and put them in your output folder.
So now my output folder looks like this:
Now you should be able to zip up everything in the output folder to a zip file (call it application.zip).
You can test if it has worked by unzipping the folder on another machine and running the executable. If your game works, it’s been packaged and deployed correctly.
3. Penultimate step: zip up your source code
Next, zip up your .cpp and .h files into a zip file called source.zip
with source.zip and application.zip inside it.
If that doesn’t work for you, this is the ‘manual’ method:https://wiki.qt.io/Deploy_an_Application_on_Windows