首页 > > 详细

COMP282代做、代写C++编程设计

项目预算:   开发周期:  发布时间:   要求地区:
University Of Liverpool Department of Computer Science
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:
(1) The source code (your cpp and h files)
(2) The application, packaged for deployment.
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.
1. Packaging your Qt application for Windows Deployment:
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 desktop
applications, 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:
cd bin
my folder looks like this (type dir /w or just dir to list the contents)
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.
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.
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
shouldn’t be an issue.
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.
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.
Method 1 – manually including the image folder
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:
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
code :
qDebug() << "Executable directory:" << QCoreApplication::applicationDirPath();.
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:
QDir directory(QCoreApplication::applicationDirPath() + "/images/animal_images");
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:
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:
windeployqt
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.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

软件开发、广告设计客服
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 9951568
© 2021 www.rj363.com
软件定制开发网!