├── CombineQMLWithQWidget ├── CarSpeed.pro ├── SpeedNeedle.qml ├── deployment.pri ├── main.cpp ├── main.qml ├── qml.qrc ├── speed.cpp ├── speed.h ├── speed.png └── speed.ui ├── ComponentFile_Example ├── ComponentFile_Example.pro ├── RoundButton.qml ├── main.cpp ├── main.qml └── qml.qrc ├── ComponentType_Example ├── ComponentType_Example.pro ├── main.cpp ├── main.qml └── qml.qrc ├── CppPluginsForQML ├── CpuInfoPlugins │ ├── cpuinfo.cpp │ ├── cpuinfo.h │ ├── cpuinfoplugins.pro │ ├── cpuinfoplugins_plugin.cpp │ ├── cpuinfoplugins_plugin.h │ └── qmldir └── TestPlugins │ ├── TestPlugins.pro │ ├── deployment.pri │ ├── main.cpp │ ├── main.qml │ └── qml.qrc ├── CreateQMLObjectInJavaScript ├── CreateQMLObject.js ├── CreateQMLObjectInJavaScript.pro ├── MyText.qml ├── main.cpp ├── main.qml └── qml.qrc ├── DefineQMLTypeFromCPP ├── DefineQMLTypeFromCPP.pro ├── cpuinfo.cpp ├── cpuinfo.h ├── deployment.pri ├── main.cpp ├── main.qml └── qml.qrc ├── Incubator_Example ├── Incubator_Example.pro ├── MyText.qml ├── main.cpp ├── main.qml └── qml.qrc ├── Loader_Example ├── Loader_Example.pro ├── MyText.qml ├── main.cpp ├── main.qml └── qml.qrc ├── QLibrary ├── MyWidget │ ├── MyWidget.pro │ ├── mywidget.cpp │ ├── mywidget.h │ └── mywidget_global.h └── Test │ ├── Test.pro │ ├── deployment.pri │ ├── main.cpp │ ├── main.qml │ └── qml.qrc ├── QQmlApplicationEngine_Example ├── QQmlApplicationEngine_Example.pro ├── main.cpp ├── main.qml └── qml.qrc ├── QQmlEngine_Example ├── QQmlEngine_Example.pro ├── main.cpp ├── main.qml └── qml.qrc ├── QQuickView_Example ├── QQuickView_Example.pro ├── main.cpp ├── main.qml └── qml.qrc ├── README.md ├── SharedLibrary ├── MyWidget │ ├── MyWidget.pro │ ├── mywidget.cpp │ ├── mywidget.h │ └── mywidget_global.h └── Test │ ├── Test.pro │ ├── deployment.pri │ ├── main.cpp │ ├── main.qml │ └── qml.qrc ├── StaticLibrary ├── MyWidget │ ├── MyWidget.pro │ ├── mywidget.cpp │ ├── mywidget.h │ └── qml.qrc └── Test │ ├── Test.pro │ ├── deployment.pri │ ├── main.cpp │ ├── main.qml │ └── qml.qrc └── main.qml /CombineQMLWithQWidget/CarSpeed.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | 3 | QT += qml quick widgets 4 | CONFIG += c++11 5 | 6 | SOURCES += main.cpp \ 7 | speed.cpp 8 | 9 | RESOURCES += qml.qrc 10 | 11 | # Additional import path used to resolve QML modules in Qt Creator's code model 12 | QML_IMPORT_PATH = 13 | 14 | # Default rules for deployment. 15 | include(deployment.pri) 16 | 17 | FORMS += \ 18 | speed.ui 19 | 20 | HEADERS += \ 21 | speed.h 22 | 23 | DISTFILES += 24 | -------------------------------------------------------------------------------- /CombineQMLWithQWidget/SpeedNeedle.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Item { 4 | id: id_root 5 | property int value: 0 6 | property int startAngle : 0 7 | property double angleLength: 0 8 | property int maxSpeed: 0 9 | 10 | Rectangle { 11 | width: id_root.height * 0.02 12 | height: id_root.height * 0.45 13 | color: "light green" 14 | anchors { 15 | horizontalCenter: id_root.horizontalCenter 16 | } 17 | antialiasing: true 18 | y: id_root.height * 0.05 19 | } 20 | 21 | rotation: value * angleLength + startAngle 22 | 23 | antialiasing: true 24 | 25 | Behavior on rotation { 26 | SmoothedAnimation { velocity: 50 } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /CombineQMLWithQWidget/deployment.pri: -------------------------------------------------------------------------------- 1 | unix:!android { 2 | isEmpty(target.path) { 3 | qnx { 4 | target.path = /tmp/$${TARGET}/bin 5 | } else { 6 | target.path = /opt/$${TARGET}/bin 7 | } 8 | export(target.path) 9 | } 10 | INSTALLS += target 11 | } 12 | 13 | export(INSTALLS) 14 | -------------------------------------------------------------------------------- /CombineQMLWithQWidget/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "ui_speed.h" 7 | #include "speed.h" 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | QApplication app(argc, argv); 12 | QQuickView view; 13 | 14 | qmlRegisterType("Speed", 1, 0, "Speed"); 15 | view.setSource(QUrl("qrc:/main.qml")); 16 | view.show(); 17 | return app.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /CombineQMLWithQWidget/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.3 2 | import Speed 1.0 3 | 4 | Rectangle { 5 | id: root 6 | width: 400 7 | height: 400 8 | color: "black" 9 | 10 | property int numberIndexs: 15 11 | property int startAngle: 234 12 | property int angleLength: 18 13 | property int maxSpeed: 280 14 | 15 | Speed { 16 | id: mySpeed 17 | } 18 | 19 | Image { 20 | anchors.fill: parent 21 | source: "speed.png" 22 | } 23 | 24 | SpeedNeedle { 25 | anchors { 26 | top: parent.top 27 | bottom: parent.bottom 28 | horizontalCenter: parent.horizontalCenter 29 | } 30 | value: mySpeed.speed 31 | startAngle: root.startAngle 32 | angleLength: root.angleLength / (root.maxSpeed / (root.numberIndexs - 1)) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /CombineQMLWithQWidget/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | speed.png 5 | SpeedNeedle.qml 6 | 7 | 8 | -------------------------------------------------------------------------------- /CombineQMLWithQWidget/speed.cpp: -------------------------------------------------------------------------------- 1 | #include "speed.h" 2 | #include "ui_speed.h" 3 | 4 | Speed::Speed() : QWidget(0), ui(new Ui::Speed) { 5 | ui->setupUi(this); 6 | connect(ui->speedSlider, SIGNAL(valueChanged(int)), this, SIGNAL(speedChanged(int))); 7 | } 8 | 9 | SpeedQML::SpeedQML(QObject *parent) : QObject(parent) { 10 | m_speed.setVisible(true); 11 | m_speedData = 0; 12 | connect(&m_speed, SIGNAL(speedChanged(int)), this, SLOT(updateSpeed(int))); 13 | } 14 | 15 | int SpeedQML::speed() const { 16 | return m_speedData; 17 | } 18 | 19 | void SpeedQML::updateSpeed(int value){ 20 | m_speedData = value; 21 | emit speedChanged(); 22 | } 23 | -------------------------------------------------------------------------------- /CombineQMLWithQWidget/speed.h: -------------------------------------------------------------------------------- 1 | #ifndef SPEED_H 2 | #define SPEED_H 3 | 4 | #include 5 | #include 6 | 7 | namespace Ui { 8 | class Speed; 9 | } 10 | 11 | class Speed : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | Speed(); 17 | 18 | signals: 19 | void speedChanged(int); 20 | 21 | private: 22 | Ui::Speed *ui; 23 | }; 24 | 25 | class SpeedQML : public QObject { 26 | Q_OBJECT 27 | 28 | Q_PROPERTY(int speed READ speed NOTIFY speedChanged) 29 | public: 30 | SpeedQML(QObject *parent = 0); 31 | int speed() const; 32 | 33 | public slots: 34 | void updateSpeed(int); 35 | 36 | signals: 37 | void speedChanged(); 38 | 39 | private: 40 | int m_speedData; 41 | Speed m_speed; 42 | }; 43 | 44 | #endif // SPEED_H 45 | -------------------------------------------------------------------------------- /CombineQMLWithQWidget/speed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaTranProgrammer/ExecuteQML/431d7ba98c39706519d4e4b984075f147498f555/CombineQMLWithQWidget/speed.png -------------------------------------------------------------------------------- /CombineQMLWithQWidget/speed.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Speed 4 | 5 | 6 | 7 | 0 8 | 0 9 | 235 10 | 75 11 | 12 | 13 | 14 | Speed 15 | 16 | 17 | false 18 | 19 | 20 | 21 | 22 | 40 23 | 30 24 | 160 25 | 22 26 | 27 | 28 | 29 | 280 30 | 31 | 32 | Qt::Horizontal 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /ComponentFile_Example/ComponentFile_Example.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | 3 | QT += qml quick 4 | CONFIG += c++11 5 | 6 | SOURCES += main.cpp 7 | 8 | RESOURCES += qml.qrc 9 | 10 | # Additional import path used to resolve QML modules in Qt Creator's code model 11 | QML_IMPORT_PATH = 12 | 13 | # Additional import path used to resolve QML modules just for Qt Quick Designer 14 | QML_DESIGNER_IMPORT_PATH = 15 | 16 | # The following define makes your compiler emit warnings if you use 17 | # any feature of Qt which as been marked deprecated (the exact warnings 18 | # depend on your compiler). Please consult the documentation of the 19 | # deprecated API in order to know how to port your code away from it. 20 | DEFINES += QT_DEPRECATED_WARNINGS 21 | 22 | # You can also make your code fail to compile if you use deprecated APIs. 23 | # In order to do so, uncomment the following line. 24 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 25 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 26 | 27 | # Default rules for deployment. 28 | qnx: target.path = /tmp/$${TARGET}/bin 29 | else: unix:!android: target.path = /opt/$${TARGET}/bin 30 | !isEmpty(target.path): INSTALLS += target 31 | -------------------------------------------------------------------------------- /ComponentFile_Example/RoundButton.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Rectangle { 4 | color: "light green" 5 | radius: width / 2 6 | 7 | MouseArea { 8 | anchors.fill: parent 9 | onClicked: Qt.quit() 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ComponentFile_Example/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QGuiApplication app(argc, argv); 8 | QQuickView view; 9 | view.setSource(QUrl("qrc:/main.qml")); 10 | QObject::connect(view.engine(), SIGNAL(quit()), &view, SLOT(close())); 11 | view.setMinimumSize(QSize(200, 200)); 12 | view.show(); 13 | return app.exec(); 14 | } 15 | -------------------------------------------------------------------------------- /ComponentFile_Example/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.3 2 | 3 | Item { 4 | anchors.fill: parent 5 | 6 | RoundButton { 7 | anchors.fill: parent 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /ComponentFile_Example/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | RoundButton.qml 5 | 6 | 7 | -------------------------------------------------------------------------------- /ComponentType_Example/ComponentType_Example.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | 3 | QT += qml quick 4 | CONFIG += c++11 5 | 6 | SOURCES += main.cpp 7 | 8 | RESOURCES += qml.qrc 9 | 10 | # Additional import path used to resolve QML modules in Qt Creator's code model 11 | QML_IMPORT_PATH = 12 | 13 | # Additional import path used to resolve QML modules just for Qt Quick Designer 14 | QML_DESIGNER_IMPORT_PATH = 15 | 16 | # The following define makes your compiler emit warnings if you use 17 | # any feature of Qt which as been marked deprecated (the exact warnings 18 | # depend on your compiler). Please consult the documentation of the 19 | # deprecated API in order to know how to port your code away from it. 20 | DEFINES += QT_DEPRECATED_WARNINGS 21 | 22 | # You can also make your code fail to compile if you use deprecated APIs. 23 | # In order to do so, uncomment the following line. 24 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 25 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 26 | 27 | # Default rules for deployment. 28 | qnx: target.path = /tmp/$${TARGET}/bin 29 | else: unix:!android: target.path = /opt/$${TARGET}/bin 30 | !isEmpty(target.path): INSTALLS += target 31 | -------------------------------------------------------------------------------- /ComponentType_Example/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QGuiApplication app(argc, argv); 8 | QQuickView view; 9 | view.setSource(QUrl("qrc:/main.qml")); 10 | QObject::connect(view.engine(), SIGNAL(quit()), &view, SLOT(close())); 11 | view.setMinimumSize(QSize(200, 200)); 12 | view.show(); 13 | return app.exec(); 14 | } 15 | -------------------------------------------------------------------------------- /ComponentType_Example/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.3 2 | 3 | Item { 4 | id: root 5 | anchors.fill: parent 6 | 7 | Component { 8 | id: redSquare 9 | Rectangle { 10 | anchors.fill: parent 11 | color: "light green" 12 | radius: width / 2 13 | MouseArea { 14 | anchors.fill: parent 15 | onClicked: Qt.quit() 16 | } 17 | } 18 | } 19 | 20 | Component.onCompleted: { 21 | redSquare.createObject(root) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ComponentType_Example/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /CppPluginsForQML/CpuInfoPlugins/cpuinfo.cpp: -------------------------------------------------------------------------------- 1 | #include "cpuinfo.h" 2 | 3 | CpuInfo::CpuInfo() 4 | { 5 | m_cpuUsage = 0; 6 | 7 | #ifdef Q_OS_WIN 8 | //get the last systemtime 9 | GetSystemTimes(&last_idleTime, &last_kernelTime, &last_userTime); 10 | #elif (defined(Q_OS_ANDROID) || defined(Q_OS_LINUX)) 11 | //get cpu first time running 12 | QFile file2("/proc/stat"); 13 | file2.open(QIODevice::ReadOnly); 14 | QByteArray line2 = file2.readLine(); 15 | file2.close(); 16 | sscanf(line2.data(), "cpu %llu %llu %llu %llu", &last_totalUser, &last_totalUserNice, &last_totalSystem, &last_totalIdle); 17 | #endif 18 | } 19 | 20 | double CpuInfo::cpuUsage() const 21 | { 22 | return m_cpuUsage; 23 | } 24 | 25 | void CpuInfo::update() 26 | { 27 | #ifdef Q_OS_WIN 28 | //update cpu 29 | GetSystemTimes( &this->idleTime, &this->kernelTime, &this->userTime); 30 | qulonglong usr, ker, idl, sys; 31 | usr = convertFileTime(userTime) - convertFileTime(last_userTime); 32 | ker = convertFileTime(kernelTime) - convertFileTime(last_kernelTime); 33 | idl = convertFileTime(idleTime) - convertFileTime(last_idleTime); 34 | sys = ker + usr; 35 | last_userTime = userTime; 36 | last_kernelTime = kernelTime; 37 | last_idleTime = idleTime; 38 | m_cpuUsage = (sys - idl) * 100 / sys; 39 | #elif (defined(Q_OS_ANDROID) || defined(Q_OS_LINUX)) 40 | //update cpu 41 | QFile file2("/proc/stat"); 42 | file2.open(QIODevice::ReadOnly); 43 | QByteArray line2 = file2.readLine(); 44 | file2.close(); 45 | sscanf(line2.data(), "cpu %llu %llu %llu %llu", &totalUser, &totalUserNice, &totalSystem, &totalIdle); 46 | 47 | double overall = totalUser - last_totalUser; 48 | overall += totalUserNice - last_totalUserNice; 49 | overall += totalSystem - last_totalSystem; 50 | 51 | double total = overall + totalIdle - last_totalIdle; 52 | last_totalUser = totalUser; 53 | last_totalUserNice = totalUserNice; 54 | last_totalSystem = totalSystem; 55 | last_totalIdle = totalIdle; 56 | 57 | m_cpuUsage = (overall / total) * 100.0; 58 | #endif 59 | 60 | emit cpuUsageChanged(); 61 | } 62 | 63 | #ifdef Q_OS_WIN 64 | qulonglong CpuInfo::convertFileTime(const FILETIME& filetime) const 65 | { 66 | ULARGE_INTEGER largeInteger; 67 | largeInteger.LowPart = filetime.dwLowDateTime; 68 | largeInteger.HighPart = filetime.dwHighDateTime; 69 | return largeInteger.QuadPart; 70 | } 71 | #endif 72 | -------------------------------------------------------------------------------- /CppPluginsForQML/CpuInfoPlugins/cpuinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef CPUINFO_H 2 | #define CPUINFO_H 3 | 4 | #include 5 | #include 6 | 7 | #ifdef Q_OS_WIN 8 | #include "Windows.h" 9 | #elif (defined(Q_OS_ANDROID) || defined(Q_OS_LINUX)) 10 | #include 11 | #include 12 | #endif 13 | 14 | class CpuInfo : public QObject 15 | { 16 | Q_OBJECT 17 | 18 | Q_PROPERTY(double cpuUsage READ cpuUsage NOTIFY cpuUsageChanged) 19 | public: 20 | CpuInfo(); 21 | 22 | double cpuUsage() const; 23 | 24 | public slots: 25 | void update(); 26 | 27 | signals: 28 | void cpuUsageChanged(); 29 | 30 | private: 31 | double m_cpuUsage; 32 | 33 | #ifdef Q_OS_WIN 34 | FILETIME idleTime; 35 | FILETIME kernelTime; 36 | FILETIME userTime; 37 | 38 | FILETIME last_idleTime; 39 | FILETIME last_kernelTime; 40 | FILETIME last_userTime; 41 | 42 | qulonglong convertFileTime(const FILETIME& filetime) const; 43 | #elif (defined(Q_OS_ANDROID) || defined(Q_OS_LINUX)) 44 | qulonglong totalUser = 0; 45 | qulonglong totalUserNice = 0; 46 | qulonglong totalSystem = 0; 47 | qulonglong totalIdle = 0; 48 | 49 | qulonglong last_totalUser = 0; 50 | qulonglong last_totalUserNice = 0; 51 | qulonglong last_totalSystem = 0; 52 | qulonglong last_totalIdle = 0; 53 | #endif 54 | }; 55 | 56 | #endif // CPUINFO_H 57 | -------------------------------------------------------------------------------- /CppPluginsForQML/CpuInfoPlugins/cpuinfoplugins.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = lib 2 | TARGET = CpuInfoPlugins 3 | QT += qml quick 4 | CONFIG += qt plugin c++11 5 | 6 | DESTDIR = ../CpuInfo 7 | TARGET = $$qtLibraryTarget($$TARGET) 8 | uri = CpuInfo 9 | 10 | # Input 11 | SOURCES += \ 12 | cpuinfoplugins_plugin.cpp \ 13 | cpuinfo.cpp 14 | 15 | HEADERS += \ 16 | cpuinfoplugins_plugin.h \ 17 | cpuinfo.h 18 | 19 | DISTFILES = qmldir 20 | 21 | !equals(_PRO_FILE_PWD_, $$OUT_PWD) { 22 | copy_qmldir.target = $$OUT_PWD/qmldir 23 | copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir 24 | copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\" 25 | QMAKE_EXTRA_TARGETS += copy_qmldir 26 | PRE_TARGETDEPS += $$copy_qmldir.target 27 | } 28 | 29 | qmldir.files=qmldir 30 | unix { 31 | installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) 32 | qmldir.path = $$installPath 33 | target.path = $$installPath 34 | INSTALLS += target qmldir 35 | } 36 | 37 | # Copy the qmldir file to the same folder as the plugin binary 38 | cpqmldir.files = qmldir 39 | cpqmldir.path = $$DESTDIR 40 | COPIES += cpqmldir 41 | -------------------------------------------------------------------------------- /CppPluginsForQML/CpuInfoPlugins/cpuinfoplugins_plugin.cpp: -------------------------------------------------------------------------------- 1 | #include "cpuinfoplugins_plugin.h" 2 | #include "cpuinfo.h" 3 | 4 | #include 5 | 6 | void CpuInfoPluginsPlugin::registerTypes(const char *uri) 7 | { 8 | // @uri CpuInfo 9 | qmlRegisterType(uri, 1, 0, "CpuInfo"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /CppPluginsForQML/CpuInfoPlugins/cpuinfoplugins_plugin.h: -------------------------------------------------------------------------------- 1 | #ifndef CPUINFOPLUGINS_PLUGIN_H 2 | #define CPUINFOPLUGINS_PLUGIN_H 3 | 4 | #include 5 | 6 | class CpuInfoPluginsPlugin : public QQmlExtensionPlugin 7 | { 8 | Q_OBJECT 9 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") 10 | 11 | public: 12 | void registerTypes(const char *uri); 13 | }; 14 | 15 | #endif // CPUINFOPLUGINS_PLUGIN_H 16 | -------------------------------------------------------------------------------- /CppPluginsForQML/CpuInfoPlugins/qmldir: -------------------------------------------------------------------------------- 1 | module CpuInfo 2 | plugin CpuInfoPlugins 3 | -------------------------------------------------------------------------------- /CppPluginsForQML/TestPlugins/TestPlugins.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | 3 | QT += qml quick 4 | CONFIG += c++11 5 | 6 | DESTDIR = ../ 7 | 8 | SOURCES += main.cpp 9 | 10 | RESOURCES += qml.qrc 11 | 12 | # Additional import path used to resolve QML modules in Qt Creator's code model 13 | QML_IMPORT_PATH = 14 | 15 | # Default rules for deployment. 16 | include(deployment.pri) 17 | -------------------------------------------------------------------------------- /CppPluginsForQML/TestPlugins/deployment.pri: -------------------------------------------------------------------------------- 1 | unix:!android { 2 | isEmpty(target.path) { 3 | qnx { 4 | target.path = /tmp/$${TARGET}/bin 5 | } else { 6 | target.path = /opt/$${TARGET}/bin 7 | } 8 | export(target.path) 9 | } 10 | INSTALLS += target 11 | } 12 | 13 | export(INSTALLS) 14 | -------------------------------------------------------------------------------- /CppPluginsForQML/TestPlugins/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QGuiApplication app(argc, argv); 8 | QQuickView view; 9 | 10 | view.setSource(QUrl("qrc:/main.qml")); 11 | view.show(); 12 | 13 | return app.exec(); 14 | } 15 | -------------------------------------------------------------------------------- /CppPluginsForQML/TestPlugins/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.3 2 | import CpuInfo 1.0 3 | 4 | Rectangle { 5 | width: 200 6 | height: 400 7 | color: "gray" 8 | 9 | CpuInfo { 10 | id: id_cpuInfo 11 | } 12 | 13 | Timer { 14 | repeat: true 15 | interval: 1000 16 | running: true 17 | 18 | onTriggered: { 19 | id_cpuInfo.update() 20 | } 21 | } 22 | 23 | Rectangle { 24 | anchors { 25 | left: parent.left 26 | right: parent.right 27 | bottom: parent.bottom 28 | } 29 | color: "blue" 30 | height: id_cpuInfo.cpuUsage * parent.height / 100 31 | } 32 | 33 | Text { 34 | text: id_cpuInfo.cpuUsage + " %" 35 | anchors.centerIn: parent 36 | font.pixelSize: 50 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /CppPluginsForQML/TestPlugins/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /CreateQMLObjectInJavaScript/CreateQMLObject.js: -------------------------------------------------------------------------------- 1 | var myText = null 2 | 3 | function createQMLObjectFromFile(){ 4 | if(myText) myText.destroy() 5 | var component = Qt.createComponent("MyText.qml"); 6 | myText = component.createObject(root, {"anchors.fill": root}); 7 | } 8 | 9 | function createQMLObjectFromString(){ 10 | if(myText) myText.destroy() 11 | myText = Qt.createQmlObject('import QtQuick 2.0; Item {anchors.fill: parent; Text { anchors.centerIn: parent; text: "This is a QML string"; font.pixelSize: 50} }', root); 12 | } 13 | -------------------------------------------------------------------------------- /CreateQMLObjectInJavaScript/CreateQMLObjectInJavaScript.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | 3 | QT += qml quick 4 | CONFIG += c++11 5 | 6 | SOURCES += main.cpp 7 | 8 | RESOURCES += qml.qrc 9 | 10 | # Additional import path used to resolve QML modules in Qt Creator's code model 11 | QML_IMPORT_PATH = 12 | 13 | # Additional import path used to resolve QML modules just for Qt Quick Designer 14 | QML_DESIGNER_IMPORT_PATH = 15 | 16 | # The following define makes your compiler emit warnings if you use 17 | # any feature of Qt which as been marked deprecated (the exact warnings 18 | # depend on your compiler). Please consult the documentation of the 19 | # deprecated API in order to know how to port your code away from it. 20 | DEFINES += QT_DEPRECATED_WARNINGS 21 | 22 | # You can also make your code fail to compile if you use deprecated APIs. 23 | # In order to do so, uncomment the following line. 24 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 25 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 26 | 27 | # Default rules for deployment. 28 | qnx: target.path = /tmp/$${TARGET}/bin 29 | else: unix:!android: target.path = /opt/$${TARGET}/bin 30 | !isEmpty(target.path): INSTALLS += target 31 | -------------------------------------------------------------------------------- /CreateQMLObjectInJavaScript/MyText.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Item { 4 | anchors.fill: parent 5 | 6 | Text{ 7 | anchors.centerIn: parent 8 | text: "This is a QML file" 9 | font.pixelSize: 50 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /CreateQMLObjectInJavaScript/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char* argv[]) 6 | { 7 | QGuiApplication app(argc,argv); 8 | QQuickView view; 9 | view.setSource(QUrl("qrc:///main.qml")); 10 | view.resize(720, 480); 11 | view.show(); 12 | return app.exec(); 13 | } 14 | -------------------------------------------------------------------------------- /CreateQMLObjectInJavaScript/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.3 2 | import "CreateQMLObject.js" as MyScript 3 | 4 | Rectangle { 5 | id: root 6 | anchors.fill: parent 7 | color: "light green" 8 | property int i: 0 9 | 10 | MouseArea { 11 | anchors.fill: parent 12 | onClicked: { 13 | if(i % 2 == 0) MyScript.createQMLObjectFromString() 14 | else MyScript.createQMLObjectFromFile() 15 | i++ 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /CreateQMLObjectInJavaScript/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | MyText.qml 5 | CreateQMLObject.js 6 | 7 | 8 | -------------------------------------------------------------------------------- /DefineQMLTypeFromCPP/DefineQMLTypeFromCPP.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | 3 | QT += qml quick 4 | CONFIG += c++11 5 | 6 | SOURCES += main.cpp \ 7 | cpuinfo.cpp 8 | 9 | RESOURCES += qml.qrc 10 | 11 | # Additional import path used to resolve QML modules in Qt Creator's code model 12 | QML_IMPORT_PATH = 13 | 14 | # Default rules for deployment. 15 | include(deployment.pri) 16 | 17 | HEADERS += \ 18 | cpuinfo.h 19 | -------------------------------------------------------------------------------- /DefineQMLTypeFromCPP/cpuinfo.cpp: -------------------------------------------------------------------------------- 1 | #include "cpuinfo.h" 2 | 3 | CpuInfo::CpuInfo() 4 | { 5 | m_cpuUsage = 0; 6 | 7 | #ifdef Q_OS_WIN 8 | //get the last systemtime 9 | GetSystemTimes(&last_idleTime, &last_kernelTime, &last_userTime); 10 | #elif (defined(Q_OS_ANDROID) || defined(Q_OS_LINUX)) 11 | //get cpu first time running 12 | QFile file2("/proc/stat"); 13 | file2.open(QIODevice::ReadOnly); 14 | QByteArray line2 = file2.readLine(); 15 | file2.close(); 16 | sscanf(line2.data(), "cpu %llu %llu %llu %llu", &last_totalUser, &last_totalUserNice, &last_totalSystem, &last_totalIdle); 17 | #endif 18 | } 19 | 20 | double CpuInfo::cpuUsage() const 21 | { 22 | return m_cpuUsage; 23 | } 24 | 25 | void CpuInfo::update() 26 | { 27 | #ifdef Q_OS_WIN 28 | //update cpu 29 | GetSystemTimes( &this->idleTime, &this->kernelTime, &this->userTime); 30 | qulonglong usr, ker, idl, sys; 31 | usr = convertFileTime(userTime) - convertFileTime(last_userTime); 32 | ker = convertFileTime(kernelTime) - convertFileTime(last_kernelTime); 33 | idl = convertFileTime(idleTime) - convertFileTime(last_idleTime); 34 | sys = ker + usr; 35 | last_userTime = userTime; 36 | last_kernelTime = kernelTime; 37 | last_idleTime = idleTime; 38 | m_cpuUsage = (sys - idl) * 100 / sys; 39 | #elif (defined(Q_OS_ANDROID) || defined(Q_OS_LINUX)) 40 | //update cpu 41 | QFile file2("/proc/stat"); 42 | file2.open(QIODevice::ReadOnly); 43 | QByteArray line2 = file2.readLine(); 44 | file2.close(); 45 | sscanf(line2.data(), "cpu %llu %llu %llu %llu", &totalUser, &totalUserNice, &totalSystem, &totalIdle); 46 | 47 | double overall = totalUser - last_totalUser; 48 | overall += totalUserNice - last_totalUserNice; 49 | overall += totalSystem - last_totalSystem; 50 | 51 | double total = overall + totalIdle - last_totalIdle; 52 | last_totalUser = totalUser; 53 | last_totalUserNice = totalUserNice; 54 | last_totalSystem = totalSystem; 55 | last_totalIdle = totalIdle; 56 | 57 | m_cpuUsage = (overall / total) * 100.0; 58 | #endif 59 | 60 | emit cpuUsageChanged(); 61 | } 62 | 63 | #ifdef Q_OS_WIN 64 | qulonglong CpuInfo::convertFileTime(const FILETIME& filetime) const 65 | { 66 | ULARGE_INTEGER largeInteger; 67 | largeInteger.LowPart = filetime.dwLowDateTime; 68 | largeInteger.HighPart = filetime.dwHighDateTime; 69 | return largeInteger.QuadPart; 70 | } 71 | #endif 72 | -------------------------------------------------------------------------------- /DefineQMLTypeFromCPP/cpuinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef CPUINFO_H 2 | #define CPUINFO_H 3 | 4 | #include 5 | #include 6 | 7 | #ifdef Q_OS_WIN 8 | #include "Windows.h" 9 | #elif (defined(Q_OS_ANDROID) || defined(Q_OS_LINUX)) 10 | #include 11 | #include 12 | #endif 13 | 14 | class CpuInfo : public QObject 15 | { 16 | Q_OBJECT 17 | 18 | Q_PROPERTY(double cpuUsage READ cpuUsage NOTIFY cpuUsageChanged) 19 | public: 20 | CpuInfo(); 21 | 22 | double cpuUsage() const; 23 | 24 | public slots: 25 | void update(); 26 | 27 | signals: 28 | void cpuUsageChanged(); 29 | 30 | private: 31 | double m_cpuUsage; 32 | 33 | #ifdef Q_OS_WIN 34 | FILETIME idleTime; 35 | FILETIME kernelTime; 36 | FILETIME userTime; 37 | 38 | FILETIME last_idleTime; 39 | FILETIME last_kernelTime; 40 | FILETIME last_userTime; 41 | 42 | qulonglong convertFileTime(const FILETIME& filetime) const; 43 | #elif (defined(Q_OS_ANDROID) || defined(Q_OS_LINUX)) 44 | qulonglong totalUser = 0; 45 | qulonglong totalUserNice = 0; 46 | qulonglong totalSystem = 0; 47 | qulonglong totalIdle = 0; 48 | 49 | qulonglong last_totalUser = 0; 50 | qulonglong last_totalUserNice = 0; 51 | qulonglong last_totalSystem = 0; 52 | qulonglong last_totalIdle = 0; 53 | #endif 54 | }; 55 | 56 | #endif // CPUINFO_H 57 | -------------------------------------------------------------------------------- /DefineQMLTypeFromCPP/deployment.pri: -------------------------------------------------------------------------------- 1 | unix:!android { 2 | isEmpty(target.path) { 3 | qnx { 4 | target.path = /tmp/$${TARGET}/bin 5 | } else { 6 | target.path = /opt/$${TARGET}/bin 7 | } 8 | export(target.path) 9 | } 10 | INSTALLS += target 11 | } 12 | 13 | export(INSTALLS) 14 | -------------------------------------------------------------------------------- /DefineQMLTypeFromCPP/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "cpuinfo.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QGuiApplication app(argc, argv); 9 | QQuickView view; 10 | 11 | qmlRegisterType("CpuInfo", 1, 0, "CpuInfo"); 12 | view.setSource(QUrl("qrc:/main.qml")); 13 | view.show(); 14 | 15 | return app.exec(); 16 | } 17 | -------------------------------------------------------------------------------- /DefineQMLTypeFromCPP/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.3 2 | import CpuInfo 1.0 3 | 4 | Rectangle { 5 | width: 200 6 | height: 400 7 | color: "gray" 8 | 9 | CpuInfo { 10 | id: id_cpuInfo 11 | } 12 | 13 | Timer { 14 | repeat: true 15 | interval: 1000 16 | running: true 17 | 18 | onTriggered: { 19 | id_cpuInfo.update() 20 | } 21 | } 22 | 23 | Rectangle { 24 | anchors { 25 | left: parent.left 26 | right: parent.right 27 | bottom: parent.bottom 28 | } 29 | color: "blue" 30 | height: id_cpuInfo.cpuUsage * parent.height / 100 31 | } 32 | 33 | Text { 34 | text: id_cpuInfo.cpuUsage + " %" 35 | anchors.centerIn: parent 36 | font.pixelSize: 50 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /DefineQMLTypeFromCPP/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /Incubator_Example/Incubator_Example.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | 3 | QT += qml quick 4 | CONFIG += c++11 5 | 6 | SOURCES += main.cpp 7 | 8 | RESOURCES += qml.qrc 9 | 10 | # Additional import path used to resolve QML modules in Qt Creator's code model 11 | QML_IMPORT_PATH = 12 | 13 | # Additional import path used to resolve QML modules just for Qt Quick Designer 14 | QML_DESIGNER_IMPORT_PATH = 15 | 16 | # The following define makes your compiler emit warnings if you use 17 | # any feature of Qt which as been marked deprecated (the exact warnings 18 | # depend on your compiler). Please consult the documentation of the 19 | # deprecated API in order to know how to port your code away from it. 20 | DEFINES += QT_DEPRECATED_WARNINGS 21 | 22 | # You can also make your code fail to compile if you use deprecated APIs. 23 | # In order to do so, uncomment the following line. 24 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 25 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 26 | 27 | # Default rules for deployment. 28 | qnx: target.path = /tmp/$${TARGET}/bin 29 | else: unix:!android: target.path = /opt/$${TARGET}/bin 30 | !isEmpty(target.path): INSTALLS += target 31 | 32 | DISTFILES += \ 33 | MyText.qml 34 | -------------------------------------------------------------------------------- /Incubator_Example/MyText.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Item { 4 | anchors.fill: parent 5 | 6 | Text{ 7 | anchors.centerIn: parent 8 | text: "This is a QML file" 9 | font.pixelSize: 50 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Incubator_Example/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char* argv[]) 6 | { 7 | QGuiApplication app(argc,argv); 8 | QQuickView view; 9 | view.setSource(QUrl("qrc:///main.qml")); 10 | view.resize(720, 480); 11 | view.show(); 12 | return app.exec(); 13 | } 14 | -------------------------------------------------------------------------------- /Incubator_Example/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.3 2 | 3 | Rectangle { 4 | id: root 5 | anchors.fill: parent 6 | color: "light green" 7 | 8 | Component.onCompleted: { 9 | var component = Qt.createComponent("MyText.qml"); 10 | var incubator = component.incubateObject(root, {"anchors.fill": root}); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Incubator_Example/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | MyText.qml 5 | 6 | 7 | -------------------------------------------------------------------------------- /Loader_Example/Loader_Example.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | 3 | QT += qml quick 4 | CONFIG += c++11 5 | 6 | SOURCES += main.cpp 7 | 8 | RESOURCES += qml.qrc 9 | 10 | # Additional import path used to resolve QML modules in Qt Creator's code model 11 | QML_IMPORT_PATH = 12 | 13 | # Additional import path used to resolve QML modules just for Qt Quick Designer 14 | QML_DESIGNER_IMPORT_PATH = 15 | 16 | # The following define makes your compiler emit warnings if you use 17 | # any feature of Qt which as been marked deprecated (the exact warnings 18 | # depend on your compiler). Please consult the documentation of the 19 | # deprecated API in order to know how to port your code away from it. 20 | DEFINES += QT_DEPRECATED_WARNINGS 21 | 22 | # You can also make your code fail to compile if you use deprecated APIs. 23 | # In order to do so, uncomment the following line. 24 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 25 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 26 | 27 | # Default rules for deployment. 28 | qnx: target.path = /tmp/$${TARGET}/bin 29 | else: unix:!android: target.path = /opt/$${TARGET}/bin 30 | !isEmpty(target.path): INSTALLS += target 31 | -------------------------------------------------------------------------------- /Loader_Example/MyText.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Item { 4 | anchors.fill: parent 5 | 6 | Text{ 7 | anchors.centerIn: parent 8 | text: "This is a QML file" 9 | font.pixelSize: 50 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Loader_Example/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QGuiApplication app(argc, argv); 8 | QQuickView view; 9 | view.setSource(QUrl("qrc:/main.qml")); 10 | view.show(); 11 | return app.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /Loader_Example/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.3 2 | 3 | Rectangle { 4 | width: 720 5 | height: 480 6 | color: "light green" 7 | 8 | Loader { 9 | id: myLoader 10 | anchors.fill: parent 11 | source: "MyText.qml" 12 | } 13 | 14 | Component { 15 | id: id_myText 16 | Item { 17 | anchors.fill: parent 18 | Text{ 19 | anchors.centerIn: parent 20 | text: "This is a Component object" 21 | font.pixelSize: 50 22 | } 23 | } 24 | } 25 | 26 | MouseArea { 27 | anchors.fill: parent 28 | onClicked: { 29 | if(myLoader.source == ""){ 30 | myLoader.sourceComponent = null 31 | myLoader.source = "MyText.qml" 32 | }else{ 33 | myLoader.source = "" 34 | myLoader.sourceComponent = id_myText 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Loader_Example/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | MyText.qml 5 | 6 | 7 | -------------------------------------------------------------------------------- /QLibrary/MyWidget/MyWidget.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2017-10-12T10:20:40 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += qml quick 8 | 9 | TARGET = MyWidget 10 | TEMPLATE = lib 11 | 12 | DEFINES += MYWIDGET_LIBRARY 13 | 14 | SOURCES += mywidget.cpp 15 | 16 | HEADERS += mywidget.h\ 17 | mywidget_global.h 18 | 19 | unix { 20 | target.path = /usr/lib 21 | INSTALLS += target 22 | } 23 | -------------------------------------------------------------------------------- /QLibrary/MyWidget/mywidget.cpp: -------------------------------------------------------------------------------- 1 | #include "mywidget.h" 2 | 3 | MyWidget* createNewWidget(QQmlEngine* engine, QObject* parent, QUrl source) 4 | { 5 | return new MyWidget(engine, parent, source); 6 | } 7 | 8 | MyWidget::MyWidget(QQmlEngine* engine, QObject* parent, QUrl source) 9 | { 10 | m_component = new QQmlComponent(engine); 11 | m_component->setData("import QtQuick 2.0; Rectangle { anchors.fill: parent; anchors.margins: 50; color: \"yellow\"; opacity: 0.5; radius: 50; Text{ anchors.centerIn: parent; text: \"New Widget\"; font.pixelSize: 50; }}", source); 12 | m_quickItem = qobject_cast(m_component->create()); 13 | m_quickItem->setParentItem(qobject_cast(parent)); 14 | } 15 | 16 | MyWidget::~MyWidget() 17 | { 18 | delete m_component; 19 | delete m_quickItem; 20 | } 21 | -------------------------------------------------------------------------------- /QLibrary/MyWidget/mywidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MYWIDGET_H 2 | #define MYWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "mywidget_global.h" 11 | 12 | class MyWidget; 13 | 14 | extern "C" MYWIDGETSHARED_EXPORT MyWidget* createNewWidget(QQmlEngine* engine, QObject* parent, QUrl source); 15 | 16 | class MYWIDGETSHARED_EXPORT MyWidget : public QObject 17 | { 18 | Q_OBJECT 19 | public: 20 | MyWidget(QQmlEngine* engine, QObject* parent, QUrl source); 21 | ~MyWidget(); 22 | 23 | private: 24 | QQmlComponent *m_component; 25 | QQuickItem *m_quickItem; 26 | }; 27 | 28 | #endif // MYWIDGET_H 29 | -------------------------------------------------------------------------------- /QLibrary/MyWidget/mywidget_global.h: -------------------------------------------------------------------------------- 1 | #ifndef MYWIDGET_GLOBAL_H 2 | #define MYWIDGET_GLOBAL_H 3 | 4 | #include 5 | 6 | #if defined(MYWIDGET_LIBRARY) 7 | # define MYWIDGETSHARED_EXPORT Q_DECL_EXPORT 8 | #else 9 | # define MYWIDGETSHARED_EXPORT Q_DECL_IMPORT 10 | #endif 11 | 12 | #endif // MYWIDGET_GLOBAL_H 13 | -------------------------------------------------------------------------------- /QLibrary/Test/Test.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | 3 | QT += qml quick 4 | CONFIG += c++11 5 | 6 | SOURCES += main.cpp 7 | 8 | RESOURCES += qml.qrc 9 | 10 | # Additional import path used to resolve QML modules in Qt Creator's code model 11 | QML_IMPORT_PATH = 12 | -------------------------------------------------------------------------------- /QLibrary/Test/deployment.pri: -------------------------------------------------------------------------------- 1 | unix:!android { 2 | isEmpty(target.path) { 3 | qnx { 4 | target.path = /tmp/$${TARGET}/bin 5 | } else { 6 | target.path = /opt/$${TARGET}/bin 7 | } 8 | export(target.path) 9 | } 10 | INSTALLS += target 11 | } 12 | 13 | export(INSTALLS) 14 | -------------------------------------------------------------------------------- /QLibrary/Test/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | typedef int (*CreateWidgetFunction)(QQmlEngine* engine, QObject* parent, QUrl source); 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | QGuiApplication app(argc,argv); 13 | 14 | QQuickView view; 15 | view.setSource(QUrl("qrc:///main.qml")); 16 | view.resize(720, 480); 17 | view.show(); 18 | 19 | QLibrary library("MyWidget.dll"); 20 | library.load(); 21 | 22 | CreateWidgetFunction newWidget = (CreateWidgetFunction) library.resolve("createNewWidget"); 23 | newWidget(view.engine(), view.rootObject(), view.source()); 24 | 25 | return app.exec(); 26 | } 27 | -------------------------------------------------------------------------------- /QLibrary/Test/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.3 2 | 3 | Rectangle { 4 | id: root 5 | anchors.fill: parent 6 | color: "black" 7 | } 8 | -------------------------------------------------------------------------------- /QLibrary/Test/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /QQmlApplicationEngine_Example/QQmlApplicationEngine_Example.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | 3 | QT += qml quick 4 | CONFIG += c++11 5 | 6 | SOURCES += main.cpp 7 | 8 | RESOURCES += qml.qrc 9 | 10 | # Additional import path used to resolve QML modules in Qt Creator's code model 11 | QML_IMPORT_PATH = 12 | 13 | # Additional import path used to resolve QML modules just for Qt Quick Designer 14 | QML_DESIGNER_IMPORT_PATH = 15 | 16 | # The following define makes your compiler emit warnings if you use 17 | # any feature of Qt which as been marked deprecated (the exact warnings 18 | # depend on your compiler). Please consult the documentation of the 19 | # deprecated API in order to know how to port your code away from it. 20 | DEFINES += QT_DEPRECATED_WARNINGS 21 | 22 | # You can also make your code fail to compile if you use deprecated APIs. 23 | # In order to do so, uncomment the following line. 24 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 25 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 26 | 27 | # Default rules for deployment. 28 | qnx: target.path = /tmp/$${TARGET}/bin 29 | else: unix:!android: target.path = /opt/$${TARGET}/bin 30 | !isEmpty(target.path): INSTALLS += target 31 | -------------------------------------------------------------------------------- /QQmlApplicationEngine_Example/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QGuiApplication app(argc, argv); 7 | 8 | QQmlApplicationEngine engine; 9 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 10 | 11 | return app.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /QQmlApplicationEngine_Example/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.3 2 | import QtQuick.Window 2.2 3 | 4 | Window { 5 | visible: true 6 | width: 640 7 | height: 480 8 | Text{ 9 | id: id_text 10 | text: qsTr("Hello World") 11 | verticalAlignment: Text.AlignVCenter 12 | anchors.centerIn: parent 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /QQmlApplicationEngine_Example/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /QQmlEngine_Example/QQmlEngine_Example.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | 3 | QT += qml quick 4 | CONFIG += c++11 5 | 6 | SOURCES += main.cpp 7 | 8 | RESOURCES += qml.qrc 9 | 10 | # Additional import path used to resolve QML modules in Qt Creator's code model 11 | QML_IMPORT_PATH = 12 | 13 | # Additional import path used to resolve QML modules just for Qt Quick Designer 14 | QML_DESIGNER_IMPORT_PATH = 15 | 16 | # The following define makes your compiler emit warnings if you use 17 | # any feature of Qt which as been marked deprecated (the exact warnings 18 | # depend on your compiler). Please consult the documentation of the 19 | # deprecated API in order to know how to port your code away from it. 20 | DEFINES += QT_DEPRECATED_WARNINGS 21 | 22 | # You can also make your code fail to compile if you use deprecated APIs. 23 | # In order to do so, uncomment the following line. 24 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 25 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 26 | 27 | # Default rules for deployment. 28 | qnx: target.path = /tmp/$${TARGET}/bin 29 | else: unix:!android: target.path = /opt/$${TARGET}/bin 30 | !isEmpty(target.path): INSTALLS += target 31 | -------------------------------------------------------------------------------- /QQmlEngine_Example/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | QGuiApplication app(argc, argv); 10 | 11 | QQmlEngine engine; 12 | QQmlContext *context = new QQmlContext(engine.rootContext()); 13 | QStringList dataList; 14 | dataList.append("Item 1"); 15 | dataList.append("Item 2"); 16 | context->setContextProperty("myModel", QVariant::fromValue(dataList)); 17 | QQmlComponent component(&engine, QUrl("qrc:/main.qml")); 18 | component.create(context); 19 | 20 | return app.exec(); 21 | } 22 | -------------------------------------------------------------------------------- /QQmlEngine_Example/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.3 2 | import QtQuick.Window 2.2 3 | 4 | Window { 5 | visible: true 6 | width: 100 7 | height: 100 8 | color: "light blue" 9 | 10 | ListView { 11 | anchors.fill: parent 12 | model: myModel 13 | delegate: Text { text: modelData } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /QQmlEngine_Example/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /QQuickView_Example/QQuickView_Example.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | 3 | QT += qml quick 4 | CONFIG += c++11 5 | 6 | SOURCES += main.cpp 7 | 8 | RESOURCES += qml.qrc 9 | 10 | # Additional import path used to resolve QML modules in Qt Creator's code model 11 | QML_IMPORT_PATH = 12 | 13 | # Additional import path used to resolve QML modules just for Qt Quick Designer 14 | QML_DESIGNER_IMPORT_PATH = 15 | 16 | # The following define makes your compiler emit warnings if you use 17 | # any feature of Qt which as been marked deprecated (the exact warnings 18 | # depend on your compiler). Please consult the documentation of the 19 | # deprecated API in order to know how to port your code away from it. 20 | DEFINES += QT_DEPRECATED_WARNINGS 21 | 22 | # You can also make your code fail to compile if you use deprecated APIs. 23 | # In order to do so, uncomment the following line. 24 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 25 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 26 | 27 | # Default rules for deployment. 28 | qnx: target.path = /tmp/$${TARGET}/bin 29 | else: unix:!android: target.path = /opt/$${TARGET}/bin 30 | !isEmpty(target.path): INSTALLS += target 31 | -------------------------------------------------------------------------------- /QQuickView_Example/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QGuiApplication app(argc, argv); 8 | QQuickView view; 9 | view.setSource(QUrl("qrc:/main.qml")); 10 | QObject::connect(view.engine(), SIGNAL(quit()), &view, SLOT(close())); 11 | view.show(); 12 | return app.exec(); 13 | } 14 | -------------------------------------------------------------------------------- /QQuickView_Example/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.3 2 | 3 | Rectangle { 4 | width: 200 5 | height: 200 6 | color: "light green" 7 | radius: width / 2 8 | 9 | MouseArea { 10 | anchors.fill: parent 11 | onClicked: Qt.quit() 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /QQuickView_Example/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ExecuteQML 2 | This workspace contains some solution to execute QML document 3 | -------------------------------------------------------------------------------- /SharedLibrary/MyWidget/MyWidget.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2017-10-12T10:20:40 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += qml quick 8 | 9 | TARGET = MyWidget 10 | TEMPLATE = lib 11 | 12 | DEFINES += MYWIDGET_LIBRARY 13 | 14 | SOURCES += mywidget.cpp 15 | 16 | HEADERS += mywidget.h\ 17 | mywidget_global.h 18 | 19 | unix { 20 | target.path = /usr/lib 21 | INSTALLS += target 22 | } 23 | -------------------------------------------------------------------------------- /SharedLibrary/MyWidget/mywidget.cpp: -------------------------------------------------------------------------------- 1 | #include "mywidget.h" 2 | 3 | 4 | MyWidget::MyWidget(QQmlEngine* engine, QObject* parent, QUrl source) 5 | { 6 | qDebug() << "MyWidget::" << Q_FUNC_INFO; 7 | m_component = new QQmlComponent(engine); 8 | m_component->setData("import QtQuick 2.0; Rectangle { anchors.fill: parent; anchors.margins: 50; color: \"yellow\"; opacity: 0.5; radius: 50; Text{ anchors.centerIn: parent; text: \"New Widget\"; font.pixelSize: 50; }}", source); 9 | m_quickItem = qobject_cast(m_component->create()); 10 | m_quickItem->setParentItem(qobject_cast(parent)); 11 | } 12 | 13 | MyWidget::~MyWidget() 14 | { 15 | qDebug() << "MyWidget::" << Q_FUNC_INFO; 16 | delete m_component; 17 | delete m_quickItem; 18 | } 19 | -------------------------------------------------------------------------------- /SharedLibrary/MyWidget/mywidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MYWIDGET_H 2 | #define MYWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "mywidget_global.h" 11 | 12 | class MYWIDGETSHARED_EXPORT MyWidget : public QObject 13 | { 14 | Q_OBJECT 15 | public: 16 | MyWidget(QQmlEngine* engine, QObject* parent, QUrl source); 17 | ~MyWidget(); 18 | 19 | private: 20 | QQmlComponent *m_component; 21 | QQuickItem *m_quickItem; 22 | }; 23 | 24 | #endif // MYWIDGET_H 25 | -------------------------------------------------------------------------------- /SharedLibrary/MyWidget/mywidget_global.h: -------------------------------------------------------------------------------- 1 | #ifndef MYWIDGET_GLOBAL_H 2 | #define MYWIDGET_GLOBAL_H 3 | 4 | #include 5 | 6 | #if defined(MYWIDGET_LIBRARY) 7 | # define MYWIDGETSHARED_EXPORT Q_DECL_EXPORT 8 | #else 9 | # define MYWIDGETSHARED_EXPORT Q_DECL_IMPORT 10 | #endif 11 | 12 | #endif // MYWIDGET_GLOBAL_H 13 | -------------------------------------------------------------------------------- /SharedLibrary/Test/Test.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | 3 | QT += qml quick 4 | CONFIG += c++11 5 | 6 | SOURCES += main.cpp 7 | 8 | RESOURCES += qml.qrc 9 | 10 | # Additional import path used to resolve QML modules in Qt Creator's code model 11 | QML_IMPORT_PATH = 12 | 13 | # Default rules for deployment. 14 | include(deployment.pri) 15 | -------------------------------------------------------------------------------- /SharedLibrary/Test/deployment.pri: -------------------------------------------------------------------------------- 1 | unix:!android { 2 | isEmpty(target.path) { 3 | qnx { 4 | target.path = /tmp/$${TARGET}/bin 5 | } else { 6 | target.path = /opt/$${TARGET}/bin 7 | } 8 | export(target.path) 9 | } 10 | INSTALLS += target 11 | } 12 | 13 | export(INSTALLS) 14 | -------------------------------------------------------------------------------- /SharedLibrary/Test/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "mywidget.h" 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | QGuiApplication app(argc,argv); 12 | 13 | QQuickView view; 14 | view.setSource(QUrl("qrc:///main.qml")); 15 | view.resize(720, 480); 16 | view.show(); 17 | 18 | MyWidget widget(view.engine(), view.rootObject(), view.source()); 19 | 20 | return app.exec(); 21 | } 22 | -------------------------------------------------------------------------------- /SharedLibrary/Test/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.3 2 | 3 | Rectangle { 4 | id: root 5 | anchors.fill: parent 6 | color: "black" 7 | } 8 | -------------------------------------------------------------------------------- /SharedLibrary/Test/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /StaticLibrary/MyWidget/MyWidget.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2017-10-10T08:49:37 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += qml quick 8 | 9 | TARGET = MyWidget 10 | TEMPLATE = lib 11 | CONFIG += staticlib 12 | 13 | SOURCES += mywidget.cpp 14 | 15 | HEADERS += mywidget.h 16 | unix { 17 | target.path = /usr/lib 18 | INSTALLS += target 19 | } 20 | 21 | RESOURCES += 22 | -------------------------------------------------------------------------------- /StaticLibrary/MyWidget/mywidget.cpp: -------------------------------------------------------------------------------- 1 | #include "mywidget.h" 2 | 3 | 4 | MyWidget::MyWidget(QQmlEngine* engine, QObject* parent, QUrl source) 5 | { 6 | m_component = new QQmlComponent(engine); 7 | m_component->setData("import QtQuick 2.0; Rectangle { anchors.fill: parent; anchors.margins: 50; color: \"yellow\"; opacity: 0.5; radius: 50; Text{ anchors.centerIn: parent; text: \"New Widget\"; font.pixelSize: 50; }}", source); 8 | m_quickItem = qobject_cast(m_component->create()); 9 | m_quickItem->setParentItem(qobject_cast(parent)); 10 | } 11 | 12 | MyWidget::~MyWidget() 13 | { 14 | delete m_component; 15 | delete m_quickItem; 16 | } 17 | -------------------------------------------------------------------------------- /StaticLibrary/MyWidget/mywidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MYWIDGET_H 2 | #define MYWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class MyWidget : public QObject 12 | { 13 | Q_OBJECT 14 | public: 15 | MyWidget(QQmlEngine* engine, QObject* parent, QUrl source); 16 | ~MyWidget(); 17 | 18 | private: 19 | QQmlComponent *m_component; 20 | QQuickItem *m_quickItem; 21 | }; 22 | 23 | #endif // MYWIDGET_H 24 | -------------------------------------------------------------------------------- /StaticLibrary/MyWidget/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /StaticLibrary/Test/Test.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | 3 | QT += qml quick 4 | CONFIG += c++11 5 | 6 | SOURCES += main.cpp 7 | 8 | RESOURCES += qml.qrc 9 | 10 | # Additional import path used to resolve QML modules in Qt Creator's code model 11 | QML_IMPORT_PATH = 12 | 13 | # Default rules for deployment. 14 | include(deployment.pri) 15 | -------------------------------------------------------------------------------- /StaticLibrary/Test/deployment.pri: -------------------------------------------------------------------------------- 1 | unix:!android { 2 | isEmpty(target.path) { 3 | qnx { 4 | target.path = /tmp/$${TARGET}/bin 5 | } else { 6 | target.path = /opt/$${TARGET}/bin 7 | } 8 | export(target.path) 9 | } 10 | INSTALLS += target 11 | } 12 | 13 | export(INSTALLS) 14 | -------------------------------------------------------------------------------- /StaticLibrary/Test/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "mywidget.h" 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | QGuiApplication app(argc,argv); 12 | 13 | QQuickView view; 14 | view.setSource(QUrl("qrc:///main.qml")); 15 | view.resize(720, 480); 16 | view.show(); 17 | 18 | MyWidget widget(view.engine(), view.rootObject(), view.source()); 19 | 20 | return app.exec(); 21 | } 22 | -------------------------------------------------------------------------------- /StaticLibrary/Test/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.3 2 | 3 | Rectangle { 4 | id: root 5 | anchors.fill: parent 6 | color: "black" 7 | } 8 | -------------------------------------------------------------------------------- /StaticLibrary/Test/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.3 2 | import QtQuick.Window 2.2 3 | 4 | Window { 5 | visible: true 6 | width: 640 7 | height: 480 8 | Text{ 9 | id: id_text 10 | text: qsTr("Hello World") 11 | verticalAlignment: Text.AlignVCenter 12 | anchors.centerIn: parent 13 | } 14 | } 15 | --------------------------------------------------------------------------------