Qml 应用程序编译 *Form.ui.qml 文件但忽略关联的 .qml 文件

Qml application compiling a *Form.ui.qml file but ignoring associated .qml file

我开发了一个与 c++ class 交互的 qml 应用程序 ui,我在 Qt Designer 中设计了 ui。所以我得到了一个 SchermataForm.ui.qml 文件和一个 Schermata.qml 文件来实现与我的 c++ class.

的交互

我的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
    }

}

您的 main.qml 实例化 SchermataForm

如果您想要 Schermata 的实例(如“Schermata.qml”中所定义),那么您需要对其进行实例化。

ApplicationWindow {
    Schermata {}
}