1. Homepage
  2. Programming
  3. COMP282 The C++ Programming Language Assignment: Qt APPLICATION DEPLOYMENT

COMP282 The C++ Programming Language Assignment: Qt APPLICATION DEPLOYMENT

Engage in a Conversation
LiverpoolCOMP282The C++ Programming LanguageC++Qt

COMP282 – The C++ Programming Language CourseNana.COM

GUIDE TO Qt APPLICATION DEPLOYMENT Document Version 1.1 CourseNana.COM

For submission of your C++ / Qt programming assignment, we require two things: (1) The source code (your cpp and h files)
(2) The application,
packaged for deployment. CourseNana.COM

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. CourseNana.COM

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. CourseNana.COM

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. CourseNana.COM

1. Packaging your Qt application for Windows Deployment: CourseNana.COM

The Windows deployment tool windeployqt automates creating a deployable folder with the necessary Qt dependencies (libraries, QML imports, plugins, and translations) to CourseNana.COM

run an application. This folder forms an installation tree suitable for Windows desktop applications, facilitating the packaging into an installer. CourseNana.COM

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: CourseNana.COM

On my laptop, I have a folder called QT on my c: drive and it looks like this: CourseNana.COM

Youll see there is a folder called 6.3.1 (which is the version of Qt I am using yours may differ). Inside that is: CourseNana.COM

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). CourseNana.COM

So in my case, my QTDIR is C:\QT\6.3.1\mingw_64\ CourseNana.COM

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\) CourseNana.COM

The deployment tool we need is called windeployqt and is in the QTDIR/bin/folder. so when in your QTDIR folder, type: CourseNana.COM

cd bin
my folder looks like this (type dir /w or just dir to list the contents) CourseNana.COM

windeployqt requires either an .exe file or a directory containing an .exe file as an argument, and examines the executable for dependencies.
It then copies any identified dependencies to the directory of the executable.
CourseNana.COM

windeployqt modifies the hardcoded local paths in Qt6Core.dll to relative ones. For Windows applications, essential compiler runtime files are also transferred to the CourseNana.COM

deployable folder by default. CourseNana.COM

The tool does not account for additional third-party libraries, such as database libraries, that the application might need. But you are not likely to have used third party libraries so this shouldnt be an issue. CourseNana.COM

Further details on additional arguments can be found in the tool's help documentation. To see that, type CourseNana.COM

windeployqt help

[If this command doesn’t work, you may need to run the script QTDIR/bin/qtenv2.bat to set it up. ] CourseNana.COM

2. Packaging resource files (e.g. image files) CourseNana.COM

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 wont work on another computer so we have to use relative pathnames and package the images folder in the correct place. CourseNana.COM

There are at least two ways to do this. I will describe both here. CourseNana.COM

How to choose the method?
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. CourseNana.COM

Method 1 manually including the image folder CourseNana.COM

The simplest way is to put your images folder into the project output folder, and then make the image filenames in the code refer to them with relative paths. We do this as follows: CourseNana.COM

Your projects 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: CourseNana.COM

build-example6-Desktop_Qt_6_3_1_MinGW_64_bit-Debug

If you want to find out what your projects output folder is you can use this in your project code : CourseNana.COM

qDebug() << "Executable directory:" << QCoreApplication::applicationDirPath();. Here you can see I have copied my images folder into my project output folder. CourseNana.COM

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: CourseNana.COM

QDir directory(C:/Users/andyrox/Documents/qt_examples/images/animal_images); becomes this: CourseNana.COM

QDir directory(QCoreApplication::applicationDirPath() + "/images/animal_images"); Check that this still works when you run the application from Qt Creator. CourseNana.COM

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:
CourseNana.COM

cd C:QT\6.3.1\mingw_64\bin

(The version number 6.3.1 may be different on your system) Then we run windeployqt. The syntax is: CourseNana.COM

windeployqt <path_to_output_folder>

In my case I would type: CourseNana.COM

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):
CourseNana.COM

Now we need to make sure that required dlls from the compilers bin folder are included in the application. You need to copy these files (highlighted in grey): CourseNana.COM

and put them in your output folder.
So now my output folder looks like this:
CourseNana.COM

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. CourseNana.COM

Method 2 Using the Resource Collection File CourseNana.COM

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:
CourseNana.COM

(1) You need to make a file called a Resource Collection File with the filename CourseNana.COM

resources.qrc

In 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, so you will need to ‘search and replace’ my paths with yours, so that they are pointing to the files on your computer.
CourseNana.COM

Here is my resources.qrc file for the playing cards: CourseNana.COM

<RCC>
<qresource prefix="/images">
CourseNana.COM

<file>C:/Users/andyrox/Documents/card_images/back/back.png</file> <file>C:/Users/andyrox/Documents/card_images/10_of_clubs.png</file> <file>C:/Users/andyrox/Documents/card_images/10_of_diamonds.png</file> <file>C:/Users/andyrox/Documents/card_images/10_of_hearts.png</file> <file>C:/Users/andyrox/Documents/card_images/10_of_spades.png</file> <file>C:/Users/andyrox/Documents/card_images/2_of_clubs.png</file> <file>C:/Users/andyrox/Documents/card_images/2_of_diamonds.png</file> <file>C:/Users/andyrox/Documents/card_images/2_of_hearts.png</file> <file>C:/Users/andyrox/Documents/card_images/2_of_spades.png</file> <file>C:/Users/andyrox/Documents/card_images/3_of_clubs.png</file> <file>C:/Users/andyrox/Documents/card_images/3_of_diamonds.png</file> <file>C:/Users/andyrox/Documents/card_images/3_of_hearts.png</file> <file>C:/Users/andyrox/Documents/card_images/3_of_spades.png</file> <file>C:/Users/andyrox/Documents/card_images/4_of_clubs.png</file> <file>C:/Users/andyrox/Documents/card_images/4_of_diamonds.png</file> <file>C:/Users/andyrox/Documents/card_images/4_of_hearts.png</file> <file>C:/Users/andyrox/Documents/card_images/4_of_spades.png</file> <file>C:/Users/andyrox/Documents/card_images/5_of_clubs.png</file> <file>C:/Users/andyrox/Documents/card_images/5_of_diamonds.png</file> <file>C:/Users/andyrox/Documents/card_images/5_of_hearts.png</file> <file>C:/Users/andyrox/Documents/card_images/5_of_spades.png</file> <file>C:/Users/andyrox/Documents/card_images/6_of_clubs.png</file> <file>C:/Users/andyrox/Documents/card_images/6_of_diamonds.png</file> <file>C:/Users/andyrox/Documents/card_images/6_of_hearts.png</file> <file>C:/Users/andyrox/Documents/card_images/6_of_spades.png</file> <file>C:/Users/andyrox/Documents/card_images/7_of_clubs.png</file> <file>C:/Users/andyrox/Documents/card_images/7_of_diamonds.png</file> <file>C:/Users/andyrox/Documents/card_images/7_of_hearts.png</file> <file>C:/Users/andyrox/Documents/card_images/7_of_spades.png</file> <file>C:/Users/andyrox/Documents/card_images/8_of_clubs.png</file> <file>C:/Users/andyrox/Documents/card_images/8_of_diamonds.png</file> <file>C:/Users/andyrox/Documents/card_images/8_of_hearts.png</file> <file>C:/Users/andyrox/Documents/card_images/8_of_spades.png</file> <file>C:/Users/andyrox/Documents/card_images/9_of_clubs.png</file> <file>C:/Users/andyrox/Documents/card_images/9_of_diamonds.png</file> <file>C:/Users/andyrox/Documents/card_images/9_of_hearts.png</file> <file>C:/Users/andyrox/Documents/card_images/9_of_spades.png</file> <file>C:/Users/andyrox/Documents/card_images/ace_of_clubs.png</file> <file>C:/Users/andyrox/Documents/card_images/ace_of_diamonds.png</file> <file>C:/Users/andyrox/Documents/card_images/ace_of_hearts.png</file> <file>C:/Users/andyrox/Documents/card_images/ace_of_spades.png</file> <file>C:/Users/andyrox/Documents/card_images/ace_of_spades2.png</file> <file>C:/Users/andyrox/Documents/card_images/black_joker.png</file> CourseNana.COM

<file>C:/Users/andyrox/Documents/card_images/jack_of_clubs.png</file> <file>C:/Users/andyrox/Documents/card_images/jack_of_clubs2.png</file> <file>C:/Users/andyrox/Documents/card_images/jack_of_diamonds.png</file> <file>C:/Users/andyrox/Documents/card_images/jack_of_diamonds2.png</file> <file>C:/Users/andyrox/Documents/card_images/jack_of_hearts.png</file> <file>C:/Users/andyrox/Documents/card_images/jack_of_hearts2.png</file> <file>C:/Users/andyrox/Documents/card_images/jack_of_spades.png</file> <file>C:/Users/andyrox/Documents/card_images/jack_of_spades2.png</file> <file>C:/Users/andyrox/Documents/card_images/king_of_clubs.png</file> <file>C:/Users/andyrox/Documents/card_images/king_of_clubs2.png</file> <file>C:/Users/andyrox/Documents/card_images/king_of_diamonds.png</file> <file>C:/Users/andyrox/Documents/card_images/king_of_diamonds2.png</file> <file>C:/Users/andyrox/Documents/card_images/king_of_hearts.png</file> <file>C:/Users/andyrox/Documents/card_images/king_of_hearts2.png</file> <file>C:/Users/andyrox/Documents/card_images/king_of_spades.png</file> <file>C:/Users/andyrox/Documents/card_images/king_of_spades2.png</file> <file>C:/Users/andyrox/Documents/card_images/queen_of_clubs.png</file> <file>C:/Users/andyrox/Documents/card_images/queen_of_clubs2.png</file> <file>C:/Users/andyrox/Documents/card_images/queen_of_diamonds.png</file> <file>C:/Users/andyrox/Documents/card_images/queen_of_diamonds2.png</file> <file>C:/Users/andyrox/Documents/card_images/queen_of_hearts.png</file> <file>C:/Users/andyrox/Documents/card_images/queen_of_hearts2.png</file> <file>C:/Users/andyrox/Documents/card_images/queen_of_spades.png</file> <file>C:/Users/andyrox/Documents/card_images/queen_of_spades2.png</file> <file>C:/Users/andyrox/Documents/card_images/red_joker.png</file> CourseNana.COM

</qresource> CourseNana.COM

</RCC> CourseNana.COM

Once you have made the resources.qrc file, put it in the project folder. In my memory card game example, the project folder looks like this: CourseNana.COM

(2) Now you need to adjust your source code so that any images that are used reference via the Resources file, instead of having an absolute pathname. CourseNana.COM

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): CourseNana.COM

QPixmap pixmap(":/images/queen_of_spades.png"); CourseNana.COM

instead of CourseNana.COM

QPixmap pixmap("C:/Users/andyrox/Documents/card_images/queen_of_spades.png</"); (3) Then we run windeployqt. The syntax is: CourseNana.COM

windeployqt <path_to_output_folder>

In my case I would type something like: CourseNana.COM

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):
CourseNana.COM

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): CourseNana.COM

and put them in your output folder.
So now my output folder looks like this:
CourseNana.COM

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. CourseNana.COM

3. Penultimate step: zip up your source code CourseNana.COM

Next, zip up your .cpp and .h files into a zip file called source.zip
4. Final step: make a zip file (e.g. assignment2.zip) CourseNana.COM

with source.zip and application.zip inside it. CourseNana.COM

You should then submit assignment2.zip. CourseNana.COM

--- --- --- --- --- CourseNana.COM

Further help if you’re stuck: CourseNana.COM

https://doc.qt.io/qt-6/windows-deployment.html CourseNana.COM

If that doesn’t work for you, this is the ‘manual’ method: CourseNana.COM

CourseNana.COM

https://wiki.qt.io/Deploy_an_Application_on_Windows  CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
Liverpool代写,COMP282代写,The C++ Programming Language代写,C++代写,Qt代写,Liverpool代编,COMP282代编,The C++ Programming Language代编,C++代编,Qt代编,Liverpool代考,COMP282代考,The C++ Programming Language代考,C++代考,Qt代考,Liverpoolhelp,COMP282help,The C++ Programming Languagehelp,C++help,Qthelp,Liverpool作业代写,COMP282作业代写,The C++ Programming Language作业代写,C++作业代写,Qt作业代写,Liverpool编程代写,COMP282编程代写,The C++ Programming Language编程代写,C++编程代写,Qt编程代写,Liverpoolprogramming help,COMP282programming help,The C++ Programming Languageprogramming help,C++programming help,Qtprogramming help,Liverpoolassignment help,COMP282assignment help,The C++ Programming Languageassignment help,C++assignment help,Qtassignment help,Liverpoolsolution,COMP282solution,The C++ Programming Languagesolution,C++solution,Qtsolution,