Model view controller 如何从qml启动.exe文件?
大家好,我必须实现基于MVC的应用程序。Model view controller 如何从qml启动.exe文件?,model-view-controller,qml,qt5.7,qqmlcomponent,qqmlapplicationengine,Model View Controller,Qml,Qt5.7,Qqmlcomponent,Qqmlapplicationengine,大家好,我必须实现基于MVC的应用程序。 如何在QML表单上加载sparate exe文件。在这种情况下,MVC是什么意思? 加载单独的exe是什么意思 如果你想从QML UI运行另一个应用程序,你需要一个C++接口/对象来完成这个任务。 main.cpp #include <QGuiApplication> #include <QQmlApplicationEngine> #include <QProcess> #include <QQmlConte
如何在QML表单上加载sparate exe文件。在这种情况下,MVC是什么意思? 加载单独的exe是什么意思 <>如果你想从QML UI运行另一个应用程序,你需要一个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"
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"
}
}
}
}