QML应用程序编译一个 *form.ui.qml文件,但忽略了关联的.qml文件



我已经构建了一个与C 类连接的QML应用程序,并且我在QT Designer中设计了UI。因此,我得到了一个schermataform.ui.qml文件和一个与我的C 类实现交互的schermata.qml文件。

我的主要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被忽略(例如:ComboBox在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
    }
}

您的main.qml实例SchermataForm

如果您想要Schermata的实例(如'Schermata.qml`中定义),则需要实例化。

ApplicationWindow {
    Schermata {}
}

最新更新