Qml 应用程序编译 *Form.ui.qml 文件但忽略关联的 .qml 文件
Posted
技术标签:
【中文标题】Qml 应用程序编译 *Form.ui.qml 文件但忽略关联的 .qml 文件【英文标题】:Qml application compiling a *Form.ui.qml file but ignoring associated .qml file 【发布时间】:2016-12-18 17:05:56 【问题描述】:我已经构建了一个与 c++ 类接口的 qml 应用程序,并且我在 Qt Designer 中设计了 ui。所以我得到了一个 SchermataForm.ui.qml 文件和一个实现与我的 c++ 类交互的 Schermata.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
【问题讨论】:
请发帖mcve 【参考方案1】:您的 main.qml 实例化 SchermataForm
。
如果您想要一个 Schermata
的实例(定义在 'Schermata.qml` 中),那么您需要实例化它。
ApplicationWindow
Schermata
【讨论】:
以上是关于Qml 应用程序编译 *Form.ui.qml 文件但忽略关联的 .qml 文件的主要内容,如果未能解决你的问题,请参考以下文章
是否可以为 android 编译 Qt+QML+OpenCV 应用程序