QSimpleUpdater
QSimpleUpdater is an implementation of an auto-updating system to be used with Qt projects.
QSimpleUpdater is free and open source LGPL software, which means that you can use it for both open source and propietary applications.
Using QSimpleUpdater
1. Import QSimpleUpdater to your project
- Copy the
QSimpleUpdater
folder in your "3rd-party" folder. - Include the QSimpleUpdater project include (pri) file using the include() function.
- That's all! Check the example project as a reference.
2. Include QSimpleUpdater in your header file(s):
#include <QSimpleUpdater>
3. Declare a new instance of QSimpleUpdater in your header file (preferably as a private object).
QSimpleUpdater *updater;
4. Initialize and configure the updater when your class is created:
MyClass::MyClass() {<span style="color: #888888">// Initialize the updater</span> updater <span style="color: #333333">=</span> <span style="color: #008800; font-weight: bold">new</span> QSimpleUpdater(<span style="color: #008800; font-weight: bold">this</span>); <span style="color: #888888">// Define our application version....</span> <span style="color: #888888">// The string must contain the same number</span> <span style="color: #888888">// of dots as the one that we will download</span> QString app_version <span style="color: #333333">=</span> <span style="background-color: #fff0f0">"1.2.3"</span> <span style="color: #888888">// This string will help us to specify which file</span> <span style="color: #888888">// should we download when a new version of the app</span> <span style="color: #888888">// is detected.</span> QString download_url; <span style="color: #888888">// The following code will help us to define from where</span> <span style="color: #888888">// we should download the binary installation file </span> <span style="color: #888888">// in the case that the updater detects a newer version</span> <span style="color: #888888">// of your app.</span> <span style="color: #888888">// Download the DMG file of your app </span> <span style="color: #FF0000; background-color: #FFAAAA">#</span>ifdef Q_OS_MAC download_url <span style="color: #333333">=</span> <span style="background-color: #fff0f0">"http://myapp.com/downloads/latest.dmg"</span>; <span style="color: #FF0000; background-color: #FFAAAA">#</span>endif <span style="color: #888888">// Download the EXE setup for your app</span> <span style="color: #FF0000; background-color: #FFAAAA">#</span>ifdef Q_OS_WIN download_url <span style="color: #333333">=</span> <span style="background-color: #fff0f0">"http://myapp.com/downloads/latest.exe"</span>; <span style="color: #FF0000; background-color: #FFAAAA">#</span>endif <span style="color: #888888">// Download a *.tar.gz file for your app</span> <span style="color: #FF0000; background-color: #FFAAAA">#</span>ifdef Q_OS_LINUX download_url <span style="color: #333333">=</span> <span style="background-color: #fff0f0">"http://myapp.com/downloads/latest.tar.gz"</span>; <span style="color: #FF0000; background-color: #FFAAAA">#</span>endif <span style="color: #888888">// Version of the installed application (in this case, 1.2.3)</span> <span style="color: #888888">// The parameter must be a QString.... </span> updater<span style="color: #333333">-></span>setApplicationVersion(app_version); <span style="color: #888888">// Tell the updater from where we should download</span> <span style="color: #888888">// the installer of our application</span> updater<span style="color: #333333">-></span>setDownloadUrl(QUrl(download_url)); <span style="color: #888888">// The following text file should only contain the </span> <span style="color: #888888">// latest application version, for example, 1.2.3 or 1.2.4</span> updater<span style="color: #333333">-></span>setReferenceUrl(QUrl(<span style="background-color: #fff0f0">"http://myapp.com/latest.txt"</span>)); <span style="color: #888888">// Tell the updater where to download the changelog...</span> updater<span style="color: #333333">-></span>setChangelogUrl(QUrl(<span style="background-color: #fff0f0">"http://myapp.com/changelog.txt"</span>)); <span style="color: #888888">// Check for updates....</span> updater<span style="color: #333333">-></span>checkForUpdates(); <span style="color: #888888">// Finally, do something when the updater finds a new version</span> <span style="color: #888888">// of your app.</span> connect(updater, SIGNAL(updateAvailable()), <span style="color: #008800; font-weight: bold">this</span>, SLOT(onUpdateAvailable()));
}
5. Define what your application should do when the updater finds a new version of your application. For example:
MyClass::onUpdateAvailable() { qDebug() << "A new version of myApp is available!"; qDebug() << "The latest version is:" << updater->latestVersion(); qDebug() << "The change log of the new version is:\n" << updater->changeLog();<span style="color: #333399; font-weight: bold">char</span> type; <span style="color: #008800; font-weight: bold">while</span> (<span style="color: #007020">true</span>) { cout <span style="color: #333333"><<</span> <span style="background-color: #fff0f0">"Download the latest version [y/n]"</span> <span style="color: #333333"><<</span> endl; cin <span style="color: #333333">>></span> type; <span style="color: #008800; font-weight: bold">if</span> ((type <span style="color: #333333">==</span> <span style="color: #0044DD">'y'</span>) <span style="color: #333333">||</span> (type <span style="color: #333333">==</span> <span style="color: #0044DD">'n'</span>)) { <span style="color: #008800; font-weight: bold">break</span>; } } <span style="color: #008800; font-weight: bold">if</span> (type <span style="color: #333333">==</span> <span style="color: #0044DD">'y'</span>) { updater<span style="color: #333333">-></span>downloadLatestVersion(); }
}
Notes
Running the example project
- Navigate to the
Example
folder and openexample.pro
with Qt Creator. - Compile the project and play with it
:)
Useful Links
Donate
Donate Bitcoins to the project to keep it going!
1BdxESMayJAengjAkjipMwfWkiqZUztyhU
Description
Languages
C++
91.8%
QMake
6.5%
Batchfile
1.1%
Shell
0.6%