Deploying Windows Applications: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
(MediaWiki Markup Cleanup)
Line 1: Line 1:
h1. Deploying Windows Applications
{{DISPLAYTITLE:Deploying Windows Applications}}
 
[toc depth="2"]


== What does that mean? ==
== What does that mean? ==
Line 12: Line 10:


Besides your compiled .exe file you need some libraries contained in the same directory as the executable.
Besides your compiled .exe file you need some libraries contained in the same directory as the executable.
All needed libraries are located in your Qt installation bin directory, e.g. '''C:.4\mingw491_32\bin'''. If you have installed more than one development kits you need to copy the libraries from the correct kit of course.
All needed libraries are located in your Qt installation bin directory, e.g. '''C:\Qt5.4\mingw491_32\bin'''. If you have installed more than one development kits you need to copy the libraries from the correct kit of course.


'''WARNING: Don't take the library files from the QtCreator directory which is compiled with MSVC and has slightly different entry points.'''
'''WARNING: Don't take the library files from the QtCreator directory which is compiled against MSVC libraries and has different entry points.'''


In either case you need the following non-Qt libraries. The list was created from a Qt 5.4 installation:
In either case you need the following non-Qt libraries. The list was created from a Qt 5.4 installation:


{background:#009900;color:white}. |''. Library Name |''. Size |_. Remarks |
{| class="wikitable" style="text-align:left;" width="50%"
|>. icudt53.dll | 21M | Unicode Lib |
! style="text-align:left;" | Library Name
|>. icuin53.dll | 3.6M | Unicode Lib |
! style="text-align:left;" | Size
|>. icuuc53.dll | 2.0M | Unicode Lib |
! style="text-align:left;" | Remarks
|>. libgcc_s_dw2-1.dll | 118K | GCC Lib |
|-
|>. libstdc+''–6.dll | 1003K | Standard C''+ Library |
| icudt53.dll || 21M || Unicode Lib
|>. libwinpthread-1.dll | 48K | Pthreads for Windows |
|-
| icuin53.dll || 3.6M || Unicode Lib
|-
| icuuc53.dll || 2.0M || Unicode Lib
|-
| libgcc_s_dw2-1.dll || 118K || GCC Lib
|-
| libstdc+''–6.dll || 1003K || Standard C''+ Library
|-
| libwinpthread-1.dll || 48K || Pthreads for Windows
|}


Some might argue that there might arise a ''small problem'' with shipping '''27M''' ICU libraries. If you don't need ICU (http://site.icu-project.org/) you need to recompile Qt with configure -without-icu.
Some might argue that there might arise a ''small problem'' with shipping '''27M''' ICU libraries. If you don't need ICU (http://site.icu-project.org/) you need to recompile Qt with <tt>./configure -without-icu</tt>.


Next we need depending on what your application needs to copy the Qt DLLs. First have a look at your .pro file that has a line like:
Next we need &mdash; depending on what your application needs &mdash; to copy the Qt DLLs. First have a look at your .pro file that has a line like:


<code>QT ''= widgets<code>
<code>QT += widgets</code>


In this case you need to copy the following files:
In this case you need to copy the following files:


{background:#009900;color:white}. |''. Library Name |''. Size |_. Remarks |
{| class="wikitable" style="text-align:left;" width="50%"
|>. Qt5Core.dll | 4.7M | Qt Core classes always needed! |
! style="text-align:left;" | Library Name
|>. Qt5Gui.dll | 5.0M | Graphical User Interface Classes |
! style="text-align:left;" | Size
|>. Qt5Widgets.dll | 6.2M | Widget Classes |
! style="text-align:left;" | Remarks
|-
| Qt5Core.dll || 4.7M || Qt Core classes &mdash; always needed!
|-
| Qt5Gui.dll || 5.0M || Graphical User Interface Classes
|-
| Qt5Widgets.dll || 6.2M || Widget Classes
|}


So far for the core libraries to make the program run on other machines. But wait. Something important is missing:
So far for the core libraries to make the program run on other machines. But wait. Something important is missing:


h2. Platform Plugins
== Platform Plugins ==


For some reason some vital functions for starting Windows applications are contained in '''qwindows.dll''' Located in '''C:.4\mingw491_32\plugins\platforms'''. Copying this file to the same directory to the other DLLs would not work. This file is expected in the '''platforms''' subdirectory:
Some vital functions for starting Windows applications are contained in '''qwindows.dll''' Located in '''C:\Qt5.4\mingw491_32\plugins\platforms'''. Copying this file to the same directory to the other DLLs would not work. This file is expected in the '''platforms''' subdirectory:


</code>
.
.
├── Qt5Core.dll
├── Qt5Core.dll
├── Qt5Gui.dll
├── Qt5Gui.dll
├── Qt5Sql.dll
├── Qt5Sql.dll
├── Qt5Widgets.dll
├── Qt5Widgets.dll
├── icudt53.dll
├── icudt53.dll
├── icuin53.dll
├── icuin53.dll
├── icuuc53.dll
├── icuuc53.dll
├── libgcc_s_dw2-1.dll
├── libgcc_s_dw2-1.dll
├── libstdc–6.dll
├── libstdc–6.dll
├── libwinpthread-1.dll
├── libwinpthread-1.dll
└── '''platforms'''
└── platforms
     └── '''qwindows.dll'''
   └── qwindows.dll
<code>


Now your application is good to go and able to run on other machines not having a fully blown Qt installation preinstalled. Unfortunately you still need to ship a total of approx. 45M (half without ICU).
Now your application is good to go and able to run on other machines not having a full blown Qt installation preinstalled. Unfortunately you still need to ship a total of approximately 45M (half without ICU).


h2. Database Applications
== Database Applications ==


When shipping applications that need to establish a database connection you need to ship the '''Qt5Sql.dll''' and the database driver library you use to connect to the database. In this example we make use of SQLite:
When shipping applications that need to establish a database connection you need to ship the '''Qt5Sql.dll''' and the database driver library you use to connect to the database. In this example we make use of SQLite:


</code>
.
.
├── Qt5Core.dll
├── Qt5Core.dll
├── Qt5Gui.dll
├── Qt5Gui.dll
├── Qt5Widgets.dll
├── Qt5Widgets.dll
├── Qt5Sql.dll
├── Qt5Sql.dll
├── icudt53.dll
├── icudt53.dll
├── icuin53.dll
├── icuin53.dll
├── icuuc53.dll
├── icuuc53.dll
├── libgcc_s_dw2-1.dll
├── libgcc_s_dw2-1.dll
├── libstdc''+–6.dll
├── libstdc''+–6.dll
├── libwinpthread-1.dll
├── libwinpthread-1.dll
├── platforms
├── platforms
│   └── qwindows.dll
│   └── qwindows.dll
└── '''sqldrivers'''
└── sqldrivers
    └── '''qsqlite.dll'''
└── qsqlite.dll
<code>


You noticed that we created a sqldrivers directory holding the sqlite.dll copied from '''C:.4\mingw491_32\plugins\sqldrivers'''
You noticed that we created a sqldrivers directory holding the sqlite.dll copied from '''C:\Qt5.4\mingw491_32\plugins\sqldrivers'''


== Building a Windows Installer ==
== Building a Windows Installer ==
Line 91: Line 102:
First head over to http://download.qt.io/official_releases/qt-installer-framework/1.5.0/ and download the package for your operating system.
First head over to http://download.qt.io/official_releases/qt-installer-framework/1.5.0/ and download the package for your operating system.


After installation — we assume *c: — we need to create some files holding the installer meta data. I suggest creating a directory in your source root directory called "installer" with this structure:
After installation we need to create some files holding the installer meta data. I suggest creating a directory in your source root directory called ''installer'' with this structure:


</code>
.
.
├── config
├── config
│   └── config.xml
│   └── config.xml
└── packages
└── packages
    └── my-package
└── my-package
        ├── data
├── data
          ├── my-executable.exe
│ ├── my-executable.exe
          ├── …
│ ├── …
          .
│ .
        └── meta
└── meta
            ├── installshortcut.qs
├── installshortcut.qs
            ├── license.txt
├── license.txt
            └── package.xml
└── package.xml
<code>


The installer can be instructed to install one or more '''packages'''. They are all located in the packages subdirectory. In the above example we have one package called '''my-package'''. In the meta directory we store the license, an installation script for the Windows Shortcut and a package.xml containing the meta data:
The installer can be instructed to install one or more '''packages'''. They are all located in the packages subdirectory. In the above example we have one package called '''my-package'''. In the meta directory we store the license, an installation script for the Windows Shortcut and a package.xml containing the meta data:
Line 113: Line 122:
package.xml contains:
package.xml contains:


</code>
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<Package>
<Package>
  <DisplayName>Name of this Package</DisplayName>
<DisplayName>Name of this Package</DisplayName>
  <Description>Short description</Description>
<Description>Short description</Description>
  <Version>1.0</Version>
<Version>1.0</Version>
  <ReleaseDate>2015-01-10</ReleaseDate>
<ReleaseDate>2015-01-10</ReleaseDate>
  <Name>convert</Name>
<Name>convert</Name>
  <Licenses>
<Licenses>
  <License name="GPL" file="license.txt" />
<License name="GPL" file="license.txt" />
  </Licenses>
</Licenses>
  <ForcedInstallation>true</ForcedInstallation>
<ForcedInstallation>true</ForcedInstallation>
  </Package>
  [removed]installshortcut.qs[removed]
</Package>
<code>


The installshortcut.qs:
The installshortcut.qs:


</code>
<code>
function Component() {
function Component() {
}
}


Component.prototype.createOperations = function() {
Component.prototype.createOperations = function() {
component.createOperations();
  component.createOperations();


if ( installer.value("os") === "win" ) {
if ( installer.value("os") === "win" ) {
component.addOperation(
  component.addOperation(
"CreateShortcut",
  "CreateShortcut",
"@TargetDir@/my-executable.exe",
  "@TargetDir@/my-executable.exe",
"@StartMenuDir@/My Executable.lnk"
  "@StartMenuDir@/My Executable.lnk"
);
  );
  }
  }
  }
}
</code>
<code>


And finally the main configuration file contained in config:
And finally the main configuration file contained in config:
Line 152: Line 158:
config.xml
config.xml


</code>
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<Installer>
<Installer>
  <Name>My Executable</Name>
<Name>My Executable</Name>
  <Version>1.0</Version>
<Version>1.0</Version>
  <Title&amp;amp;gt;Description&amp;amp;lt;/Title&amp;amp;gt;
<Title&amp;amp;gt;Description&amp;amp;lt;/Title&amp;amp;gt;
  <Publisher>Simon Wilper</Publisher>
<Publisher>Simon Wilper</Publisher>
  <StartMenuDir>My Application</StartMenuDir>
<StartMenuDir>My Application</StartMenuDir>
  <TargetDir>@rootDir@my-application</TargetDir>
<TargetDir>@rootDir@my-application</TargetDir>
  <UninstallerName>Uninstall</UninstallerName>
<UninstallerName>Uninstall</UninstallerName>
</Installer>
</Installer>
<code>


Now to create the installer run the binarycreator:
Now to create the installer run the binarycreator:


</code>
c:\qtinstfw\bin\binarycreator.exe —offline-only -c config\config.xml -p packages setup.exe
c:.exe —offline-only -c config\config.xml -p packages setup.exe
<code>

Revision as of 00:49, 28 February 2015


What does that mean?

In most cases the Qt applications you create don't reside on your development machine just to please you. You want to distribute them and make them run without any further hazzle and dependency installations on any Windows machine: Copy, Double-Click and Run.

Normally Qt applications are compiled and linked against shared libraries (Windows: DLL=Dynamic Link Library, Unix: .so=Shared Object). When the compiled program is executed the code from the libraries needed is loaded at runtime. The point is now to know which libraries have to be shipped along with your application to make it run without having a full Qt installation on the target system.

List of Libraries needed

Besides your compiled .exe file you need some libraries contained in the same directory as the executable. All needed libraries are located in your Qt installation bin directory, e.g. C:\Qt5.4\mingw491_32\bin. If you have installed more than one development kits you need to copy the libraries from the correct kit of course.

WARNING: Don't take the library files from the QtCreator directory which is compiled against MSVC libraries and has different entry points.

In either case you need the following non-Qt libraries. The list was created from a Qt 5.4 installation:

Library Name Size Remarks
icudt53.dll 21M Unicode Lib
icuin53.dll 3.6M Unicode Lib
icuuc53.dll 2.0M Unicode Lib
libgcc_s_dw2-1.dll 118K GCC Lib
libstdc+–6.dll 1003K Standard C+ Library
libwinpthread-1.dll 48K Pthreads for Windows

Some might argue that there might arise a small problem with shipping 27M ICU libraries. If you don't need ICU (http://site.icu-project.org/) you need to recompile Qt with ./configure -without-icu.

Next we need — depending on what your application needs — to copy the Qt DLLs. First have a look at your .pro file that has a line like:

QT += widgets

In this case you need to copy the following files:

Library Name Size Remarks
Qt5Core.dll 4.7M Qt Core classes — always needed!
Qt5Gui.dll 5.0M Graphical User Interface Classes
Qt5Widgets.dll 6.2M Widget Classes

So far for the core libraries to make the program run on other machines. But wait. Something important is missing:

Platform Plugins

Some vital functions for starting Windows applications are contained in qwindows.dll Located in C:\Qt5.4\mingw491_32\plugins\platforms. Copying this file to the same directory to the other DLLs would not work. This file is expected in the platforms subdirectory:

.
├── Qt5Core.dll
├── Qt5Gui.dll
├── Qt5Sql.dll
├── Qt5Widgets.dll
├── icudt53.dll
├── icuin53.dll
├── icuuc53.dll
├── libgcc_s_dw2-1.dll
├── libstdc–6.dll
├── libwinpthread-1.dll
└── platforms
    └── qwindows.dll

Now your application is good to go and able to run on other machines not having a full blown Qt installation preinstalled. Unfortunately you still need to ship a total of approximately 45M (half without ICU).

Database Applications

When shipping applications that need to establish a database connection you need to ship the Qt5Sql.dll and the database driver library you use to connect to the database. In this example we make use of SQLite:

.
├── Qt5Core.dll
├── Qt5Gui.dll
├── Qt5Widgets.dll
├── Qt5Sql.dll
├── icudt53.dll
├── icuin53.dll
├── icuuc53.dll
├── libgcc_s_dw2-1.dll
├── libstdc+–6.dll
├── libwinpthread-1.dll
├── platforms
│   └── qwindows.dll
└── sqldrivers
    └── qsqlite.dll

You noticed that we created a sqldrivers directory holding the sqlite.dll copied from C:\Qt5.4\mingw491_32\plugins\sqldrivers

Building a Windows Installer

First head over to http://download.qt.io/official_releases/qt-installer-framework/1.5.0/ and download the package for your operating system.

After installation we need to create some files holding the installer meta data. I suggest creating a directory in your source root directory called installer with this structure:

.
├── config
│   └── config.xml
└── packages
    └── my-package
        ├── data
        │   ├── my-executable.exe
        │   ├── …
        │   .
        └── meta
            ├── installshortcut.qs
            ├── license.txt
            └── package.xml

The installer can be instructed to install one or more packages. They are all located in the packages subdirectory. In the above example we have one package called my-package. In the meta directory we store the license, an installation script for the Windows Shortcut and a package.xml containing the meta data:

package.xml contains:

<?xml version="1.0" encoding="UTF-8"?>
<Package>
  <DisplayName>Name of this Package</DisplayName>
  <Description>Short description</Description>
  <Version>1.0</Version>
  <ReleaseDate>2015-01-10</ReleaseDate>
  <Name>convert</Name>
  <Licenses>
  <License name="GPL" file="license.txt" />
  </Licenses>
  <ForcedInstallation>true</ForcedInstallation>
</Package>

The installshortcut.qs:

 function Component() {
 }

 Component.prototype.createOperations = function() {
  component.createOperations();

 if ( installer.value("os") === "win" ) {
  component.addOperation(
  "CreateShortcut",
  "@TargetDir@/my-executable.exe",
  "@StartMenuDir@/My Executable.lnk"
  );
  }
 }

And finally the main configuration file contained in config:

config.xml

<?xml version="1.0" encoding="UTF-8"?>
<Installer>
  <Name>My Executable</Name>
  <Version>1.0</Version>
  <Title&amp;gt;Description&amp;lt;/Title&amp;gt;
  <Publisher>Simon Wilper</Publisher>
  <StartMenuDir>My Application</StartMenuDir>
  <TargetDir>@rootDir@my-application</TargetDir>
  <UninstallerName>Uninstall</UninstallerName>
</Installer>

Now to create the installer run the binarycreator:

c:\qtinstfw\bin\binarycreator.exe —offline-only -c config\config.xml -p packages setup.exe