//restarthandler.h:
#ifndef RESTARTHANDLER_H
#define RESTARTHANDLER_H
#include <QObject>
class RestartHandler : public QObject
{
Q_OBJECT
public:
explicit RestartHandler(QObject *parent = 0);
Q_INVOKABLE void restart();
signals:
public slots:
};
#endif // RESTARTHANDLER_H
/**********************************************************************************************************************************/
//restarthandler.cpp
#include "restarthandler.h"
#include <QCoreApplication>
RestartHandler::RestartHandler(QObject *parent) :
QObject(parent)
{
}
void RestartHandler::restart()
{
QCoreApplication::instance()->exit(773);
}
/********************************************************************************************************************************/
//main.cpp
#include <QGuiApplication>
#include <QProcess>
#include <QQmlApplicationEngine>
#include <QQmlComponent>
#include "restarthandler.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
qmlRegisterType<RestartHandler>("RestartHandler", 1, 0, "RestartHandler");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
int ret = app.exec();
if (ret == 773) {
QProcess::startDetached(qApp->applicationFilePath(), QStringList());
return 0;
}
return ret;
}
/********************************************************************************************************************************/
//Round.qml
import QtQuick 2.0
Rectangle {
id: round
height: 40
width: height
radius: height / 2
color: active === true ? 'orangered' : 'lightgrey'
property int index
property bool active: Math.random() * 100 < 10 ? true : false
signal clicked
MouseArea {
anchors.fill: parent
onClicked: {
round.active = true;
round.clicked();
}
}
}
/*******************************************************************************************************************************/
//startPage.qml
import QtQuick 2.0
Image {
id: container
source: "qrc:///images/btn_start.png"
width: 480
height: 640
signal start;
MouseArea {
width: container.width / 2
height: container.height / 5
<