答えて

1

この場合、MVCとはどういう意味ですか? load 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" 
      } 
     } 
    } 
} 
関連する問題