CVB++ 15.0
Cvb/QmlFirmwareUpdater

This example requires Qt5 >= 5.9 setup for building.

You may build it with Ubuntu 18.04's default Qt5 after installing:

1// ---------------------------------------------------------------------------
4// ---------------------------------------------------------------------------
5
6#include <iostream>
7
8#include <QApplication>
9#include <QIcon>
10#include <QMetaType>
11#include <QQmlContext>
12#include <QQuickStyle>
13#include <QQuickView>
14
15#include "backend.hpp"
16
17int main(int argc, char *argv[])
18{
19 try
20 {
21 QQuickStyle::setStyle("Windows");
22 QQuickStyle::setFallbackStyle("Universal");
23 QApplication app(argc, argv);
24 app.setOrganizationName("STEMMER IMAGING");
25 app.setOrganizationDomain("https://www.stemmer-imaging.com/");
26 app.setApplicationName("FirmwareUpdater C++ tutorial");
27
28 QQuickView *view = new QQuickView;
29 view->setResizeMode(QQuickView::SizeRootObjectToView);
30 view->setIcon(QIcon(":/qttutorial.png"));
31
32 view->resize(640, 390);
33 view->show();
34
35 // Set context property before creating QML file
36 BackEnd be(view);
37 view->rootContext()->setContextProperty("backEnd", &be);
38
39 // Load main QML file
40 view->setSource(QUrl::fromLocalFile("../main.qml"));
41
42 return app.exec();
43 }
44 catch (const std::exception &error)
45 {
46 std::cout << error.what() << std::endl;
47 }
48}
void setApplicationName(const QString &application)
void setOrganizationDomain(const QString &orgDomain)
void setOrganizationName(const QString &orgName)
void setContextProperty(const QString &name, QObject *value)
void setResizeMode(QQuickView::ResizeMode)
QQmlContext * rootContext() const const
void setSource(const QUrl &url)
QUrl fromLocalFile(const QString &localFile)
void resize(const QSize &newSize)
void setIcon(const QIcon &icon)
void show()

UI definition using QML.

1import QtQuick 2.3
2import QtQuick.Controls 2.2
3import QtQuick.Layouts 1.3
4import QtQuick.Dialogs 1.2
5import QtQuick.Controls.Universal 2.2
6
7GroupBox {
8 id: gridBox
9 width: 640
10 height: 390
11 Layout.fillWidth: true
12 Layout.fillHeight: true
13
14 property var loadFile: true
15 property var enableSnapSend: false
16
17 Universal.theme: Universal.System
18
19 background: Rectangle {
20 width: parent.width
21 height: parent.height
22 color: Universal.background
23 }
24
25 function urlToPath(urlString) {
26 var s
27 if (urlString.startsWith("file:///")) {
28 var k = urlString.charAt(9) === ':' ? 8 : 7
29 s = urlString.substring(k)
30 } else {
31 s = urlString
32 }
33 return decodeURIComponent(s);
34 }
35
36 FileDialog
37 {
38 id: fileDialog
39 modality: Qt.NonModal
40 title: loadFile ? "Select an image or driver to load" : "Save image"
41 selectExisting: loadFile
42 selectFolder: false
43 nameFilters: ["Firmware Update Files (*.guf)", "All files (*)"]
44 sidebarVisible: true
45 onAccepted:
46 {
47 var path = urlToPath(fileUrl.toString());
48 backEnd.BtnOpenGuf(path)
49 }
50 }
51
52 property alias statusText: status.text
53 GridLayout {
54 id: gridLayout
55 rows: 4
56 columns: 3
57 flow: GridLayout.TopToBottom
58 anchors.fill: parent
59
60 Text
61 {
62 text: qsTr("QmlFirmwareUpdater Example. First select a .guf file which should be used
63to update the device. Then click \"Scan\" to list all connected devices. After selecting the
64desired camera/update combination, \"Start Update\". Wait for the update to finish and
65keep the camera connected during the whole process.")
66
67 horizontalAlignment: Text.AlignHCenter
68 Layout.columnSpan: 3
69 Layout.fillWidth: true
70 }
71
72 Button
73 {
74 objectName: "btnOpenGuf"
75 id: btnOpenGuf
76 text: qsTr("Open guf file")
77 onClicked:
78 {
79 loadFile = true
80 fileDialog.open()
81 }
82 }
83
84 Button
85 {
86 objectName: "btnScan"
87 id: btnScan
88 implicitWidth: btnOpenGuf.width
89 text: qsTr("Scan")
90 onClicked:
91 {
92 backEnd.BtnScan()
93 }
94 }
95
96 Button
97 {
98 objectName: "btnStartUpdate"
99 id: btnUpdate
100 text: qsTr("Start Update")
101 onClicked:
102 {
103 backEnd.BtnStartUpdate(gufEntriesCombo.currentIndex, cameraCombo.currentText)
104 }
105 }
106
107 ComboBox
108 {
109 id: gufEntriesCombo
110 Layout.fillWidth: true
111 model: backEnd.GufEntriesCombo
112 onCurrentIndexChanged: backEnd.UpdateGufEntryInfo(gufEntriesCombo.currentIndex)
113 }
114
115 ComboBox
116 {
117 id: cameraCombo
118 Layout.fillWidth: true
119 Layout.columnSpan: 2
120 model: backEnd.CameraCombo
121 }
122
123 Label
124 {
125 id: status
126 objectName: "status"
127 text: qsTr("")
128 Layout.fillWidth: true
129 Layout.columnSpan: 2
130 }
131
132 Label
133 {
134 id: gufContent
135 objectName: "gufContent"
136 text: qsTr("")
137 }
138 }
139}