Browse Source

Add hot reload

master
pouya 1 year ago
parent
commit
e964ea8782
  1. 4
      SepantaUIKit.pro
  2. 27
      SepantaUiKit/Colors.qml
  3. 14
      app.cpp
  4. 21
      app.h
  5. 20
      main.cpp
  6. 15
      main.qml

4
SepantaUIKit.pro

@ -5,6 +5,7 @@ QT += quick
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
app.cpp \
main.cpp
RESOURCES += qml.qrc
@ -19,3 +20,6 @@ QML_DESIGNER_IMPORT_PATH =
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += \
app.h

27
SepantaUiKit/Colors.qml

@ -2,22 +2,21 @@ import QtQuick 2.15
Item {
//Primary
property var primaryEnable: "#B2F7EF"
property var primaryPressed: "#3CFCE6"
property string primaryEnable: "#B2F7EF"
property string primaryPressed: "#3CFCE6"
//Secondary
property var secondaryEnable: "#007dff"
property string secondaryEnable: "#007dff"
property var secondaryPressed: "#abb5be"
property string secondaryPressed: "#abb5be"
//Tertiary
property var tertiaryEnable: "#E9E8E8"
property var tertiaryPressed: "#D0D0d0
"
property string tertiaryEnable: "#E9E8E8"
property string tertiaryPressed: "#D0D0d0"
//Other
property var white: "#f8f8f8"
property var balck: "#0b0b0b"
property var success: "#28a745"
property var danger: "#dc3545"
property var warning: "#ffc107"
property var info: "#17a2b8"
property var gray: "#ced4da"
property string white: "#f8f8f8"
property string balck: "#0b0b0b"
property string success: "#28a745"
property string danger: "#dc3545"
property string warning: "#ffc107"
property string info: "#17a2b8"
property string gray: "#ced4da"
}

14
app.cpp

@ -0,0 +1,14 @@
#include "app.h"
#include <qdebug.h>
App::App(QObject *parent): QObject (parent)
{
}
App::~App(){}
void App::loadQml()
{
m_engine->load("");
m_engine->load("qrc:/main.qml");
}

21
app.h

@ -0,0 +1,21 @@
#ifndef APP_H
#define APP_H
#include <QObject>
#include <QQmlApplicationEngine>
class App: public QObject
{
Q_OBJECT
public:
App(QObject* parent = Q_NULLPTR);
~App();
Q_INVOKABLE void loadQml();
void setEngine(QQmlApplicationEngine *engine) { m_engine = engine; }
private:
QQmlApplicationEngine* m_engine;
};
#endif // APP_H

20
main.cpp

@ -1,25 +1,19 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "app.h"
int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreated,
&app,
[url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
},
Qt::QueuedConnection);
engine.load(url);
engine.load("qrc:/main.qml");
App appy;
appy.setEngine(&engine);
engine.rootContext()->setContextProperty("app",&appy);
return app.exec();
}

15
main.qml

@ -1,10 +1,21 @@
import QtQuick 2.13
import QtQuick.Window 2.13
import "./SepantaUiKit/SKBtn"
import QtQuick.Window 2.11
Window {
width: 1700
height: 900
id: window
width: 1600
height: 800
visible: true
title: "SepantaUiKit"
color: "black"
Shortcut {
sequence: "F5"
onActivated: {
window.close()
app.loadQml()
}
}
}

Loading…
Cancel
Save