-3
Hallo an alle ich muss implementieren MVC basierte App. So laden Sie sparete exe Datei auf QML Form.Wie starte ich eine .exe-Datei von qml?
Hallo an alle ich muss implementieren MVC basierte App. So laden Sie sparete exe Datei auf QML Form.Wie starte ich eine .exe-Datei von qml?
Was bedeutet MVC in diesem Fall? Welche mittlere Last trennen exe?
Wenn Sie eine andere Anwendung von einem QML-UI ausführen möchten, benötigen Sie eine C++ - Schnittstelle/-Objekt, die dies tun kann. main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QProcess>
#include <QQmlContext>
class ProcessStarter : public QProcess {
Q_OBJECT
public slots:
void run(const QString &application) {
startDetached(application);
}
};
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
ProcessStarter starter;
engine.rootContext()->setContextProperty("starter", &starter);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
#include "main.moc"
main.qml
import QtQuick 2.5
import QtQuick.Window 2.2
Window {
id: window
visible: true
width: 200
height: 200
title: qsTr("Hello World")
TextEdit {
id: textEdit
height: 20
text: qsTr("Enter some path to a binary and click red area")
anchors.right: parent.right
anchors.left: parent.left
verticalAlignment: Text.AlignVCenter
}
Rectangle {
id: rectangle
x: 0
y: 20
width: window.width
height: window.height - 20
color: "#d02626"
MouseArea {
id: mouseArea
anchors.fill: parent
}
Text {
id: text1
anchors.centerIn: parent
}
Connections {
target: mouseArea
onClicked: {
starter.run(textEdit.text)
text1.text = textEdit.text + " started"
}
}
}
}