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. [Solved]Using Loader multiple times.
Forum Update on Monday, May 27th 2025

[Solved]Using Loader multiple times.

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 2 Posters 3.3k 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.
  • J Offline
    J Offline
    Julie1986
    wrote on last edited by
    #1

    I have a basic program and I used Loader to load a new qml page. It works fine, when I come back to the main page and again click an icon the page is unable to load. Do you know the reason behind it?

    @ectangle {
    id:main
    width: 400
    height: 400
    x:0
    color:"lightsteelblue"
    Loader { id: pageLoader
    anchors.fill:main
    }
    Loader { id: pageLoader1
    anchors.fill:main
    }

    Image {
        id: image1_main
        x: 52
        y: 71
        width: 66
        height: 52
        source: "abc.png"
        visible:true
    
    
    
    
            MouseArea {
                anchors.fill: parent
                onClicked: {pageLoader.source = "Page1.qml"
                image1_main.visible=false
                image2.visible=false
    
    
                }
            }
    
    }
    
    Image {
        id: image2
        x: 270
        y: 71
        width: 66
        height: 52
        source: "def.jpg"
        visible:true
    
    
        MouseArea {
            anchors.fill: parent
            onClicked: {pageLoader1.source = "Page2.qml"
            image1_main.visible=false
                image2.visible=false
    
    
            }
        }
    }
    

    }@

    Thanks for your time.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Why are you using 2 different loader elements, then? They probably obscure one another, you need to tweak "z" values, or better: use a single loader and change it's source on mouse click.

      (Z(:^

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Julie1986
        wrote on last edited by
        #3

        I removed one of the loader , still am not able to load page1.qml more than once. in page1.qml i have a back button which brings me to the same page(main page) again, and when i click on image1 both image1 and image2 disappear which is ok, but page1.qml is not loading.

        Clicking on image1 and image2 alternatively is working bt if i click on image1 twice, it does not give the required result.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Hm. Several possible issues here. First, move the remaining Loader after the Images in the code, or at least make it's 'z' value higher. This way you will not need to make the images invisible anymore - one chore less.

          Please share the code handling this "Back" button, it's likely to be the cause of our problems. What it should do is to trigger a change of Loader's source to "" (empty string) - this will properly destroy the page that is being loaded. This can be achieved through a signal-slot connection, for example (Loader's item sends the signal, main Rectangle receives it and resets the Loader).

          Sorry if it's hard to follow, but I'm shooting blanks at the moment - we need to pinpoint the exact issue before I can provide a definite solution.

          (Z(:^

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Julie1986
            wrote on last edited by
            #5

            Clicking on image1 and image2 alternatively is working bt if i click on image1 twice, it does not give the required result.

            I added to back button to empty the loadersource and it is working fine.
            Thanks:)

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              OK, so I misunderstood slightly. -I still have not seen the Back button handling, but never mind-. For now, try this:
              @
              pageLoader.source = ""
              pageLoader.source = "Page1.qml"
              @

              In the onClicked code for both Images. Loader is caching currently held items, that might interfere here.

              (Z(:^

              1 Reply Last reply
              0
              • sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #7

                Ah, ok, great :) Happy further coding!

                Please prepend "[Solved]" to this topic's subject, maybe it will help someone else, too.

                (Z(:^

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  Julie1986
                  wrote on last edited by
                  #8

                  @MouseArea{
                  anchors.fill:parent
                  onClicked:{ p1.visible=false
                  image1_main.visible=true
                  image2.visible=true
                  pageLoader.source=""
                  }@
                  I have a question : On emptying the loader source, will it store the current changes tat I have made in the Page1.qml file? Is there any solution to store the changes??

                  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