Skip to content

Commit 56c43b7

Browse files
committed
Updated example
1 parent 0370678 commit 56c43b7

File tree

6 files changed

+244
-1
lines changed

6 files changed

+244
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
TEMPLATE = subdirs
22

3-
SUBDIRS += WidgetsUpdater
3+
SUBDIRS += WidgetsUpdater simpleUpdaterGui
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "mainwindow.h"
2+
#include <QApplication>
3+
#include <QTranslator>
4+
#include <QLocale>
5+
#include <QLibraryInfo>
6+
7+
int main(int argc, char *argv[])
8+
{
9+
QApplication a(argc, argv);
10+
11+
//Translate app
12+
QString locale = QLocale::system().name().section('_', 0, 0);
13+
QTranslator translator;
14+
translator.load(QString("qt_") + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
15+
16+
a.installTranslator(&translator);
17+
18+
//Translate updater
19+
QTranslator translatorUpdater;
20+
21+
translatorUpdater.load(QString("translations/qtautoupdatergui_") + locale + QString(".qm"));
22+
23+
a.installTranslator(&translatorUpdater);
24+
25+
//Launch GUI
26+
MainWindow w;
27+
28+
w.show();
29+
30+
return a.exec();
31+
}
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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef MAINWINDOW_H
2+
#define MAINWINDOW_H
3+
4+
#include <QMainWindow>
5+
#include <QDebug>
6+
#include <QtAutoUpdaterGui>
7+
#include <QtAutoUpdaterGui/UpdateController>
8+
#include <QtAutoUpdaterGui/UpdateButton>
9+
10+
namespace Ui {
11+
class MainWindow;
12+
}
13+
14+
class MainWindow : public QMainWindow
15+
{
16+
Q_OBJECT
17+
18+
public:
19+
explicit MainWindow(QWidget *parent = 0);
20+
~MainWindow();
21+
22+
private:
23+
Ui::MainWindow *ui;
24+
QtAutoUpdater::UpdateController *controller;
25+
QtAutoUpdater::UpdateButton *updateButton;
26+
27+
private slots:
28+
void initializeUpdater();
29+
void checkUpdate();
30+
};
31+
32+
#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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#-------------------------------------------------
2+
#
3+
# Project created by QtCreator 2017-08-10T22:02:40
4+
#
5+
#-------------------------------------------------
6+
7+
QT += core gui widgets autoupdatergui
8+
CONFIG += C++11
9+
10+
TARGET = simpleUpdaterGui
11+
12+
TEMPLATE = app
13+
14+
SOURCES += \
15+
main.cpp \
16+
mainwindow.cpp
17+
18+
HEADERS += \
19+
mainwindow.h
20+
21+
FORMS += \
22+
mainwindow.ui
23+
24+
target.path = $$[QT_INSTALL_EXAMPLES]/autoupdatergui/WidgetsUpdater
25+
INSTALLS += target
26+
27+
#not found by linker?
28+
unix:!mac {
29+
LIBS += -L$$OUT_PWD/../../../lib #required to make this the first place to search
30+
LIBS += -L$$[QT_INSTALL_LIBS] -licudata
31+
LIBS += -L$$[QT_INSTALL_LIBS] -licui18n
32+
LIBS += -L$$[QT_INSTALL_LIBS] -licuuc
33+
}
34+
35+
#add lib dir to rpath
36+
mac: QMAKE_LFLAGS += '-Wl,-rpath,\'$$OUT_PWD/../../../lib\''

0 commit comments

Comments
 (0)