Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. load two file qml
Forum Updated to NodeBB v4.3 + New Features

load two file qml

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 2 Posters 983 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vale88
    wrote on last edited by vale88
    #1

    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

    1 Reply Last reply
    0
    • Pradeep P NP Offline
      Pradeep P NP Offline
      Pradeep P N
      wrote on last edited by Pradeep P N
      #2

      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

      Pradeep Nimbalkar.
      Upvote the answer(s) that helped you to solve the issue...
      Keep code clean.

      V 2 Replies Last reply
      2
      • Pradeep P NP Pradeep P N

        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

        V Offline
        V Offline
        vale88
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • Pradeep P NP Pradeep P N

          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

          V Offline
          V Offline
          vale88
          wrote on last edited by
          #4

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

          Cattura.PNG

          in mainwindow this:

          Cattura1.PNG

          Pradeep P NP 1 Reply Last reply
          0
          • V vale88

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

            Cattura.PNG

            in mainwindow this:

            Cattura1.PNG

            Pradeep P NP Offline
            Pradeep P NP Offline
            Pradeep P N
            wrote on last edited by
            #5

            @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 Nimbalkar.
            Upvote the answer(s) that helped you to solve the issue...
            Keep code clean.

            V 1 Reply Last reply
            1
            • Pradeep P NP Pradeep P N

              @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

              V Offline
              V Offline
              vale88
              wrote on last edited by
              #6

              @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"));
              
              
              Pradeep P NP 1 Reply Last reply
              0
              • V vale88

                @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"));
                
                
                Pradeep P NP Offline
                Pradeep P NP Offline
                Pradeep P N
                wrote on last edited by
                #7

                @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 Nimbalkar.
                Upvote the answer(s) that helped you to solve the issue...
                Keep code clean.

                V 1 Reply Last reply
                1
                • Pradeep P NP Pradeep P N

                  @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.

                  V Offline
                  V Offline
                  vale88
                  wrote on last edited by
                  #8

                  @Pradeep-P-N

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

                  Pradeep P NP 1 Reply Last reply
                  0
                  • V vale88

                    @Pradeep-P-N

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

                    Pradeep P NP Offline
                    Pradeep P NP Offline
                    Pradeep P N
                    wrote on last edited by Pradeep P N
                    #9

                    @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 Nimbalkar.
                    Upvote the answer(s) that helped you to solve the issue...
                    Keep code clean.

                    V 1 Reply Last reply
                    1
                    • Pradeep P NP Pradeep P N

                      @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.

                      V Offline
                      V Offline
                      vale88
                      wrote on last edited by vale88
                      #10

                      @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 NP 1 Reply Last reply
                      0
                      • V vale88

                        @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 NP Offline
                        Pradeep P NP Offline
                        Pradeep P N
                        wrote on last edited by
                        #11

                        @vale88

                        0ea42916-5ba7-46bd-a942-99beaebf8dc5-image.png

                        Pradeep Nimbalkar.
                        Upvote the answer(s) that helped you to solve the issue...
                        Keep code clean.

                        V 1 Reply Last reply
                        1
                        • Pradeep P NP Pradeep P N

                          @vale88

                          0ea42916-5ba7-46bd-a942-99beaebf8dc5-image.png

                          V Offline
                          V Offline
                          vale88
                          wrote on last edited by vale88
                          #12

                          @Pradeep-P-N uff...for me it isn't..maybe is it compiler?
                          can you send me code modified? also do connections work?

                          Pradeep P NP 1 Reply Last reply
                          0
                          • V vale88

                            @Pradeep-P-N uff...for me it isn't..maybe is it compiler?
                            can you send me code modified? also do connections work?

                            Pradeep P NP Offline
                            Pradeep P NP Offline
                            Pradeep P N
                            wrote on last edited by
                            #13

                            @vale88 sure. I can.
                            Are you sure you don't have qml errors warnings. ?

                            Pradeep Nimbalkar.
                            Upvote the answer(s) that helped you to solve the issue...
                            Keep code clean.

                            V 1 Reply Last reply
                            1
                            • Pradeep P NP Pradeep P N

                              @vale88 sure. I can.
                              Are you sure you don't have qml errors warnings. ?

                              V Offline
                              V Offline
                              vale88
                              wrote on last edited by
                              #14

                              @Pradeep-P-N yes I have a warning:
                              Cattura.PNG

                              1 Reply Last reply
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved