Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Loading multiple QML files via single button (click by click)
Forum Updated to NodeBB v4.3 + New Features

Loading multiple QML files via single button (click by click)

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 3 Posters 771 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.
  • A Offline
    A Offline
    ACaldas
    wrote on last edited by ACaldas
    #1

    Hi all,
    I have a column with some loaders inside and would like to call these files via "myButton", but one by one instead of a single shot. Is it possible to add this condition to myButton so it can differentiate or ordinate every click? Thanks.

    main.qml:

    Item {
      myButton {
        onClicked: loader.source = "MyWidget.qml"
      }
      Loader {
        id: loader1
        anchors.fill: parent
      }
    }
    
    1 Reply Last reply
    0
    • qtprogrammer123Q Offline
      qtprogrammer123Q Offline
      qtprogrammer123
      wrote on last edited by qtprogrammer123
      #2

      Button{

      property int i:  0
      property int n: 3 //number of QML files for load
                  
      onClicked: {
                      
          if(i === 0) loader.source = "MyWidget.qml"
          if(i === 1) loader.source = "MyWidget1.qml"
          if(i === 2) loader.source = "MyWidget2.qml"
          ...
          if(i === n) loader.source = "MyWidgetn.qml"
                                
          i = (i == n ? 0 : ++i)
                      
      }
      

      }

      Mam moc jak Harry Potter, w zębach mogę przenieść hotel.

      A 3 Replies Last reply
      1
      • qtprogrammer123Q qtprogrammer123

        Button{

        property int i:  0
        property int n: 3 //number of QML files for load
                    
        onClicked: {
                        
            if(i === 0) loader.source = "MyWidget.qml"
            if(i === 1) loader.source = "MyWidget1.qml"
            if(i === 2) loader.source = "MyWidget2.qml"
            ...
            if(i === n) loader.source = "MyWidgetn.qml"
                                  
            i = (i == n ? 0 : ++i)
                        
        }
        

        }

        A Offline
        A Offline
        ACaldas
        wrote on last edited by
        #3

        @qtprogrammer123 Thank you so much!

        1 Reply Last reply
        1
        • qtprogrammer123Q qtprogrammer123

          Button{

          property int i:  0
          property int n: 3 //number of QML files for load
                      
          onClicked: {
                          
              if(i === 0) loader.source = "MyWidget.qml"
              if(i === 1) loader.source = "MyWidget1.qml"
              if(i === 2) loader.source = "MyWidget2.qml"
              ...
              if(i === n) loader.source = "MyWidgetn.qml"
                                    
              i = (i == n ? 0 : ++i)
                          
          }
          

          }

          A Offline
          A Offline
          ACaldas
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • qtprogrammer123Q qtprogrammer123

            Button{

            property int i:  0
            property int n: 3 //number of QML files for load
                        
            onClicked: {
                            
                if(i === 0) loader.source = "MyWidget.qml"
                if(i === 1) loader.source = "MyWidget1.qml"
                if(i === 2) loader.source = "MyWidget2.qml"
                ...
                if(i === n) loader.source = "MyWidgetn.qml"
                                      
                i = (i == n ? 0 : ++i)
                            
            }
            

            }

            A Offline
            A Offline
            ACaldas
            wrote on last edited by ACaldas
            #5

            @qtprogrammer123 do you have idea on how to do the way back? I mean unload them one by one? Thanks. Couldn't find anything about.

            These lines below can't work properly as the 3 loaders are inactive by the "removeButton" I'm not able to lead them again.

            MyRemoveButton {
            ...
            property int i: 0
            property int n: 3 //number of QML files for load
                     onClicked: {
                                    if(i === 0) loader3.active = false
                                    if(i === 1) loader2.active = false
                                    if(i === 2) loader1.active = false
            
                                    i = (i == n ? 0 : ++i)
                                 }
                      }
            }
            
            MarkkyboyM qtprogrammer123Q 2 Replies Last reply
            0
            • A ACaldas

              @qtprogrammer123 do you have idea on how to do the way back? I mean unload them one by one? Thanks. Couldn't find anything about.

              These lines below can't work properly as the 3 loaders are inactive by the "removeButton" I'm not able to lead them again.

              MyRemoveButton {
              ...
              property int i: 0
              property int n: 3 //number of QML files for load
                       onClicked: {
                                      if(i === 0) loader3.active = false
                                      if(i === 1) loader2.active = false
                                      if(i === 2) loader1.active = false
              
                                      i = (i == n ? 0 : ++i)
                                   }
                        }
              }
              
              MarkkyboyM Offline
              MarkkyboyM Offline
              Markkyboy
              wrote on last edited by
              #6

              @ACaldas - a clue or two from here; maybe this helps; https://forum.qt.io/topic/10814/how-to-terminate-or-hide-a-qml-using-loader/9

              Don't just sit there standing around, pick up a shovel and sweep up!

              I live by the sea, not in it.

              1 Reply Last reply
              1
              • A ACaldas

                @qtprogrammer123 do you have idea on how to do the way back? I mean unload them one by one? Thanks. Couldn't find anything about.

                These lines below can't work properly as the 3 loaders are inactive by the "removeButton" I'm not able to lead them again.

                MyRemoveButton {
                ...
                property int i: 0
                property int n: 3 //number of QML files for load
                         onClicked: {
                                        if(i === 0) loader3.active = false
                                        if(i === 1) loader2.active = false
                                        if(i === 2) loader1.active = false
                
                                        i = (i == n ? 0 : ++i)
                                     }
                          }
                }
                
                qtprogrammer123Q Offline
                qtprogrammer123Q Offline
                qtprogrammer123
                wrote on last edited by
                #7

                @ACaldas
                if(i === 0) loader3.active = !loader.3.active
                if(i === 1) loader2.active = !loader.2.active
                if(i === 2) loader1.active = !loader.2.active

                Mam moc jak Harry Potter, w zębach mogę przenieść hotel.

                A 1 Reply Last reply
                1
                • qtprogrammer123Q qtprogrammer123

                  @ACaldas
                  if(i === 0) loader3.active = !loader.3.active
                  if(i === 1) loader2.active = !loader.2.active
                  if(i === 2) loader1.active = !loader.2.active

                  A Offline
                  A Offline
                  ACaldas
                  wrote on last edited by
                  #8

                  @qtprogrammer123 Thank you.

                  The loading and unloading process is working fine but after unloading the last source nothing happens. There should be a way to make this reusable. Would you know how to fix this?

                  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