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

190 views Asked by At

I've built a qml application that interfaces with a c++ class, and I designed the ui in Qt Designer. so I got a SchermataForm.ui.qml file and a Schermata.qml file that implements the interactions with my c++ class.

my main.qml is as follows:

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 {}
    }

and my 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();
}

When I run the application it seems Schermata.qml is ignored (e.g.: the combobox shows its elements if they are set inside SchermataForm.ui.qml, but doesn't if they are set in Schermata.qml) and I don't understand why.

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
    }

}
1

There are 1 answers

0
Kevin Krammer On BEST ANSWER

Your main.qml instantiates SchermataForm.

If you want an instance of Schermata (as defined in 'Schermata.qml`) then you need to instantiate that.

ApplicationWindow {
    Schermata {}
}