Solved load two file qml
-
I wrote:
ui->quickWidget->setSource(QUrl("qrc:///qml.qml")); ui->quickWidget_2->setSource(QUrl("qrc:///sl.qml"));
but the second isn't loaded..
my sl.qml is:
import QtQuick 2.0 import QtQuick.Extras 1.4 import QtGraphicalEffects 1.0 import QtQuick.Window 2.10 Item { Dial { id: dial x: 197 y: 94 } }
my project:
-
Hi @vale88
Can you please provide
width
&height
for yourItem { }
.
You can even directly useDial {}
withoutItem {}
.Sample code :
- CPP
Widget::Widget(QWidget *parent) : QWidget(parent) , _HBLyt(new QHBoxLayout(this)) , _qml1(new QQuickWidget) , _qml2(new QQuickWidget) { _qml1->setSource(QUrl::fromLocalFile(":/One.qml")); _qml2->setSource(QUrl::fromLocalFile(":/Two.qml")); _HBLyt->addWidget(_qml1); _HBLyt->addWidget(_qml2); }
- QML
- One.qml & Two.qml
import QtQuick 2.9 import QtQuick.Extras 1.4 Item { width: 100; height: 100 Dial { } } -------------------------- import QtQuick 2.9 Rectangle { width: 100; height: 100 color: 'red' }
Result of my sample:
All the best
-
This post is deleted! -
@Pradeep-P-N it's strange because in qml I have this image:
in mainwindow this:
-
@vale88
Can you please share me yourDial {}
sample code if possible ?Below is the result of using Customizing Dial.
-
import QtQuick 2.0 import QtQuick.Extras 1.4 import QtGraphicalEffects 1.0 import QtQuick.Window 2.10 import QtQuick.Controls 2.3 Item{ x: 10 y: 0 width:100 height:100 Dial{ id: control from:0 to:100 background: Rectangle { x: 5 y: 5 width: 70 height:70 color: "black" radius: width / 2 transformOrigin: Item.Right border.color: control.pressed ? "#17a81a" : "#21be2b" opacity: control.enabled ? 1 : 0.3 } // handle: Rectangle { // id: handleItem // x: control.background.x + control.background.width / 2 - width / 2 // y: control.background.y + control.background.height / 2 - height / 2 // width: 12 // height: 12 // color: "white" // radius: 8 // antialiasing: true // opacity: control.enabled ? 1 : 0.3 // transform: [ // Translate { // y: -Math.min(control.background.width, control.background.height) * 0.4 + handleItem.height / 2 // }, // Rotation { // angle: control.angle // origin.x: handleItem.width / 2 // origin.y: handleItem.height / 2 // } // ] // } Connections { target: yourObject1 onSliderMoved: control.value = (position) } } }
I have also problem with connection..in mainwindow.cpp I wrote:
ui->quickWidget->engine()->rootContext()->setContextProperty("yourObject",ui->horizontalSlider); ui->quickWidget_2->engine()->rootContext()->setContextProperty("yourObject1",ui->horizontalSlider_3); ui->quickWidget->setSource(QUrl("qrc:///qml.qml")); ui->quickWidget_2->setSource(QUrl("qrc:///sl.qml"));
-
@vale88
It looks fine for me,I have just used your code. and just removed the
Connection {}
to SliderAll the best.
-
I don't understand, I have problems when I show my qml dial in mainwindow
-
- Which platform and Qt you are using. I am working with Qt 5.9.8 on Windows
- Do you have any
warnings
orerrors
in your Application Output ?
Below is with
Connections {}
- QSliderAll the best.
-
@Pradeep-P-N qt creator with MSCV compiler,
I saw that if I use two different projects it works, but I have two files qml with connection and it doesn't work
can I send you my project? -
-
@Pradeep-P-N uff...for me it isn't..maybe is it compiler?
can you send me code modified? also do connections work? -
@vale88 sure. I can.
Are you sure you don't have qml errors warnings. ? -
@Pradeep-P-N yes I have a warning: