2016-12-18 7 views
-1

私は、C++クラスとインターフェイスするqmlアプリケーションを構築しました。私はQt Designerでuiを設計しました。 SchermataForm.ui.qmlファイルとSchermata.qmlファイルを取得して、C++クラスとのやりとりを実装しています。* Form.ui.qmlファイルをコンパイルして関連する.qmlファイルを無視するQmlアプリケーション

次のように私のmain.qmlがある:

import QtQuick 2.4 
import QtQuick.Window 2.2 
import QtQuick.Controls 2.0 
import QtQuick.Layouts 1.0 

ApplicationWindow { 
    visible: true 
    width: 1200 
    height: 600 
    title: qsTr("Simulazione Scimmia") 
    SchermataForm {} 
    } 

と私のmain.cppに:私は、アプリケーションを実行すると

#include <QQuickView> 
#include <QGuiApplication> 
#include <QQmlContext> 
#include <QQmlApplicationEngine> 
#include "grafica.h" 
int main(int argc, char *argv[]) 
{ 
    QGuiApplication app(argc, argv); 
    grafica evoluzione; 
    QQmlApplicationEngine engine(QUrl("qrc:/main.qml")); 
    QQmlContext* ctx = engine.rootContext(); 
    ctx->setContextProperty("evoluzione", &evoluzione); 

    return app.exec(); 
} 

例えば(Schermata.qmlは無視されているようだ:コンボボックスショーその要素がSchermataForm.ui.qmlの中に設定されていても、Schermata.qmlに設定されていればその要素はありません。なぜか分かりません。

Schermata.qml:

import QtQuick 2.4 

SchermataForm{ 
    button2.checkable: evoluzione.runable 
    button2.onCheckedChanged: { 
     if (button2.checked) 
      evoluzione.start_evo() 
     else 
      evoluzione.stop_evo() 
     console.log("yoo") 
    } 
    comboBox.model: ["Rita", "Lorenzo"] 
    comboBox.onCurrentIndexChanged: evoluzione.f_index = comboBox.currentIndex; 
    button1.onClicked: evoluzione.newgen() 
    parete.onClicked: evoluzione.chage_parete() 
    passi.onValueChanged:{ 
     evoluzione.passi = passi.value 
     evoluzione.set_runable() 
    } 
    individui.onValueChanged:{ 
     evoluzione.individui = individui.value 
     evoluzione.set_runable() 
    } 
    pcross.onValueChanged: evoluzione.pcross = pcross.value 
    pmuta.onValueChanged: evoluzione.pmuta=pmuta.value 
    text1.text: evoluzione.fit 
    busyIndicator.running: evoluzione.running 
} 

Schermata.ui.qml:

import QtQuick 2.4 
import QtQuick.Controls 2.0 
import QtQuick.Layouts 1.3 
import QtQuick.Extras 1.4 

Item { 
    id: item1 
    width: 1200 
    height: 600 
    property alias text1: text1 
    property alias parete: parete 
    property alias individui: individui 
    property alias passi: passi 
    property alias pcross: pcross 
    property alias pmuta: pmuta 
    property alias busyIndicator: busyIndicator 
    property alias button2: button2 
    property alias button1: button1 
    property alias comboBox: comboBox 

    RowLayout { 
     id: rowLayout 
     x: 0 
     y: 8 
     width: 863 
     height: 40 
     anchors.right: columnLayout.left 
     anchors.rightMargin: 6 
     anchors.leftMargin: 0 
     anchors.left: parent.left 
     anchors.top: parent.top 
     anchors.topMargin: 0 



     Button { 
      id: button2 
      text: qsTr("Running") 
     } 

     Button { 
      id: button1 
      text: qsTr("New Pop") 
     } 






     Button { 
      id: parete 
      text: qsTr("New Parete") 
     } 





     ComboBox { 
      id: comboBox 
      currentIndex: 0 
     } 




    } 

    ColumnLayout { 
     id: columnLayout 
     x: 869 
     y: 0 
     width: 314 
     height: 207 
     anchors.right: parent.right 
     anchors.rightMargin: 17 
     anchors.topMargin: 0 
     anchors.top: parent.top 
     z: 1 
     Layout.fillHeight: false 

     Slider { 
      id: pmuta 
      width: parent.width 
      value: 0.5 

      Label { 
       id: label3 
       x: -136 
       y: 65 
       text: qsTr("pmuta") 
       anchors.bottomMargin: -9 
       anchors.bottom: parent.bottom 
       anchors.horizontalCenter: parent.horizontalCenter 
      } 
     } 

     Slider { 
      id: pcross 
      width: parent.width 
      value: 0.5 

      Label { 
       id: label2 
       x: -136 
       y: 65 
       text: qsTr("pcross") 
       anchors.bottomMargin: -9 
       anchors.bottom: parent.bottom 
       anchors.horizontalCenter: parent.horizontalCenter 
      } 
     } 

     Slider { 
      id: passi 
      width: parent.width 
      from: 0 
      to: 2000 
      value: 500 

      Label { 
       id: label1 
       x: -136 
       y: 65 
       text: qsTr("passi") 
       horizontalAlignment: Text.AlignHCenter 
       wrapMode: Text.WordWrap 
       anchors.bottomMargin: -9 
       anchors.bottom: parent.bottom 
       anchors.horizontalCenter: parent.horizontalCenter 
      } 
     } 

     Slider { 
      id: individui 
      width: parent.width 
      to: 1000 
      value: 100 

      Label { 
       id: label 
       text: qsTr("individui") 
       anchors.horizontalCenter: parent.horizontalCenter 
       anchors.bottom: parent.bottom 
       anchors.bottomMargin: -9 
      } 
     } 



    } 

    BusyIndicator { 
     id: busyIndicator 
     x: 484 
     y: 193 
    } 

    Text { 
     id: text1 
     x: 501 
     y: 146 
     text: qsTr("Text") 
     fontSizeMode: Text.Fit 
     font.pixelSize: 12 
    } 

} 
+0

[mcve](http://stackoverflow.com/help/mcve) – folibis

答えて

0

あなたmain.qmlがSchermataFormをインスタンス化します。

Schermata( 'Schermata.qml`で定義されているように)のインスタンスを作成する場合は、インスタンス化する必要があります。

ApplicationWindow { 
    Schermata {} 
} 
関連する問題