-3
안녕하세요 여러분 모두 구현해야합니다 MVC 기반 앱입니다. sparate exe 파일을 QML 형태로로드하십시오.qml에서 .exe 파일을 시작하는 방법은 무엇입니까?
안녕하세요 여러분 모두 구현해야합니다 MVC 기반 앱입니다. sparate exe 파일을 QML 형태로로드하십시오.qml에서 .exe 파일을 시작하는 방법은 무엇입니까?
이 경우 MVC는 무엇을 의미합니까? 로드가 별도의 exe 인 것은 무엇입니까?
QML에서 다른 응용 프로그램을 실행하려는 경우이를 수행 할 수있는 C++ 인터페이스/개체가 필요합니다. 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"
}
}
}
}