Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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:

    Cattura.PNG



  • Hi @vale88

    Can you please provide width & height for your Item { }.
    You can even directly use Dial {} without Item {}.

    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:

    07297350-ec8d-4ca8-bde4-885e557b4d6b-image.png

    All the best



  • This post is deleted!


  • @Pradeep-P-N it's strange because in qml I have this image:

    Cattura.PNG

    in mainwindow this:

    Cattura1.PNG



  • @vale88
    Can you please share me your Dial {} sample code if possible ?

    Below is the result of using Customizing Dial.

    464af003-dfd6-4566-a593-f526530574ba-image.png



  • @Pradeep-P-N

    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 Slider

    bba9dd0f-c2d8-4f19-b1e0-445b36d0babc-image.png

    All the best.



  • @Pradeep-P-N

    I don't understand, I have problems when I show my qml dial in mainwindow



  • @vale88

    • Which platform and Qt you are using. I am working with Qt 5.9.8 on Windows
    • Do you have any warnings or errors in your Application Output ?

    Below is with Connections {} - QSlider

    1ae3b127-3405-45d5-9586-3d537cd19a14-image.png

    All 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:
    Cattura.PNG


Log in to reply