[Solved]Using Loader multiple times.



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


  • Moderators

    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.



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


  • Moderators

    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.



  • 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:)


  • Moderators

    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.


  • Moderators

    Ah, ok, great :) Happy further coding!

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



  • @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??


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.