Skip to content

Commit 2ae1eee

Browse files
authored
Added simple gui example
1 parent 1da525f commit 2ae1eee

File tree

5 files changed

+245
-0
lines changed

5 files changed

+245
-0
lines changed

examples/simpleUpdaterGui/main.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "mainwindow.h"
2+
#include <QApplication>
3+
4+
//Translation libraries
5+
#include <QTranslator>
6+
#include <QLocale>
7+
#include <QLibraryInfo>
8+
9+
int main(int argc, char *argv[])
10+
{
11+
QApplication a(argc, argv);
12+
13+
//Translate app
14+
QString locale = QLocale::system().name().section('_', 0, 0);
15+
QTranslator translator;
16+
translator.load(QString("qt_") + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
17+
18+
a.installTranslator(&translator);
19+
20+
//Translate updater
21+
QTranslator translatorUpdater;
22+
23+
translatorUpdater.load(QString("translations/qtautoupdatergui_") + locale + QString(".qm"));
24+
25+
a.installTranslator(&translatorUpdater);
26+
27+
//Launch GUI
28+
MainWindow w;
29+
30+
w.show();
31+
32+
return a.exec();
33+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "mainwindow.h"
2+
#include "ui_mainwindow.h"
3+
4+
MainWindow::MainWindow(QWidget *parent) :
5+
QMainWindow(parent),
6+
ui(new Ui::MainWindow),
7+
controller(nullptr), //add this
8+
updateButton(new QtAutoUpdater::UpdateButton(this)) //and this for the updater
9+
{
10+
ui->setupUi(this);
11+
12+
updateButton->setVisible(false); //The updateButton is not visible
13+
initializeUpdater(); //Initialize the updater
14+
15+
controller->start(QtAutoUpdater::UpdateController::InfoLevel); //Search for updates. Display a message if updates found, otherwise do nothing
16+
17+
connect(ui->checkUpdateButton, SIGNAL(clicked()), this, SLOT(checkUpdate())); //Connect the checkUpdateButton button to the checkUpdate method (starts the update check process)
18+
connect(ui->actionCheck_for_updates_2, SIGNAL(triggered(bool)), this, SLOT(checkUpdate())); //Connect the actionCheck_for_updates_2 to the method (starts the update check process)
19+
}
20+
21+
MainWindow::~MainWindow()
22+
{
23+
delete ui;
24+
}
25+
26+
//Initialize the updater
27+
void MainWindow::initializeUpdater()
28+
{
29+
controller = new QtAutoUpdater::UpdateController("maintenancetool.exe", qApp); //Updater app name
30+
controller->setDetailedUpdateInfo(true);
31+
updateButton->setController(controller);
32+
}
33+
34+
//Starts update check process
35+
void MainWindow::checkUpdate()
36+
{
37+
controller->start(QtAutoUpdater::UpdateController::ProgressLevel); //Check for updates. Displays a progress bar when searching
38+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef MAINWINDOW_H
2+
#define MAINWINDOW_H
3+
4+
#include <QMainWindow>
5+
#include <QDebug>
6+
7+
//QtAutoUpdater libraries
8+
#include <QtAutoUpdaterGui>
9+
#include <QtAutoUpdaterGui/UpdateController>
10+
#include <QtAutoUpdaterGui/UpdateButton>
11+
12+
namespace Ui {
13+
class MainWindow;
14+
}
15+
16+
class MainWindow : public QMainWindow
17+
{
18+
Q_OBJECT
19+
20+
public:
21+
explicit MainWindow(QWidget *parent = 0);
22+
~MainWindow();
23+
24+
private:
25+
Ui::MainWindow *ui;
26+
QtAutoUpdater::UpdateController *controller;
27+
QtAutoUpdater::UpdateButton *updateButton;
28+
29+
private slots:
30+
void initializeUpdater();
31+
void checkUpdate();
32+
};
33+
34+
#endif // MAINWINDOW_H
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>MainWindow</class>
4+
<widget class="QMainWindow" name="MainWindow">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>442</width>
10+
<height>324</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>MainWindow</string>
15+
</property>
16+
<widget class="QWidget" name="centralWidget">
17+
<layout class="QVBoxLayout" name="verticalLayout">
18+
<item>
19+
<widget class="QLabel" name="label">
20+
<property name="text">
21+
<string>Software tests updates.&lt;br/&gt;The software looks for updates when launching the application.&lt;br/&gt;If updates are found then the Update utility opens, otherwise nothing happens.</string>
22+
</property>
23+
<property name="alignment">
24+
<set>Qt::AlignCenter</set>
25+
</property>
26+
</widget>
27+
</item>
28+
<item>
29+
<widget class="QPushButton" name="checkUpdateButton">
30+
<property name="text">
31+
<string>Check for updates</string>
32+
</property>
33+
</widget>
34+
</item>
35+
<item>
36+
<widget class="QPushButton" name="quitButton">
37+
<property name="text">
38+
<string>Quit</string>
39+
</property>
40+
</widget>
41+
</item>
42+
</layout>
43+
</widget>
44+
<widget class="QMenuBar" name="menuBar">
45+
<property name="geometry">
46+
<rect>
47+
<x>0</x>
48+
<y>0</y>
49+
<width>442</width>
50+
<height>21</height>
51+
</rect>
52+
</property>
53+
<widget class="QMenu" name="menuAbout">
54+
<property name="title">
55+
<string>About</string>
56+
</property>
57+
<addaction name="actionCheck_for_updates_2"/>
58+
</widget>
59+
<addaction name="menuAbout"/>
60+
</widget>
61+
<widget class="QToolBar" name="mainToolBar">
62+
<attribute name="toolBarArea">
63+
<enum>TopToolBarArea</enum>
64+
</attribute>
65+
<attribute name="toolBarBreak">
66+
<bool>false</bool>
67+
</attribute>
68+
</widget>
69+
<widget class="QStatusBar" name="statusBar"/>
70+
<action name="actionCheck_for_updates">
71+
<property name="text">
72+
<string>Check for updates</string>
73+
</property>
74+
</action>
75+
<action name="actionCheck_Updates">
76+
<property name="text">
77+
<string>Check Updates</string>
78+
</property>
79+
</action>
80+
<action name="actionCheck_for_updates_2">
81+
<property name="text">
82+
<string>Check for updates</string>
83+
</property>
84+
</action>
85+
</widget>
86+
<layoutdefault spacing="6" margin="11"/>
87+
<resources/>
88+
<connections>
89+
<connection>
90+
<sender>quitButton</sender>
91+
<signal>clicked()</signal>
92+
<receiver>MainWindow</receiver>
93+
<slot>close()</slot>
94+
<hints>
95+
<hint type="sourcelabel">
96+
<x>177</x>
97+
<y>241</y>
98+
</hint>
99+
<hint type="destinationlabel">
100+
<x>240</x>
101+
<y>193</y>
102+
</hint>
103+
</hints>
104+
</connection>
105+
</connections>
106+
</ui>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#-------------------------------------------------
2+
#
3+
# Project created by QtCreator 2017-08-10T22:02:40
4+
#
5+
#-------------------------------------------------
6+
7+
QT += core gui
8+
9+
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets autoupdatergui
10+
11+
TARGET = simpleUpdaterGui
12+
TEMPLATE = app
13+
14+
# The following define makes your compiler emit warnings if you use
15+
# any feature of Qt which as been marked as deprecated (the exact warnings
16+
# depend on your compiler). Please consult the documentation of the
17+
# deprecated API in order to know how to port your code away from it.
18+
DEFINES += QT_DEPRECATED_WARNINGS
19+
20+
# You can also make your code fail to compile if you use deprecated APIs.
21+
# In order to do so, uncomment the following line.
22+
# You can also select to disable deprecated APIs only up to a certain version of Qt.
23+
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
24+
25+
26+
SOURCES += \
27+
main.cpp \
28+
mainwindow.cpp
29+
30+
HEADERS += \
31+
mainwindow.h
32+
33+
FORMS += \
34+
mainwindow.ui

0 commit comments

Comments
 (0)