When QML Loader is loading a file show a wait dialog



  • Hi,

    I have a pretty slow embedded target device and some QML files that I want to load dynamically. To load them dynamically I use QML Loader:

    @
    Loader {
    source: "pretty_big.qml"
    }
    @

    When the pretty_big QML is loading I want to show a dialog telling the user the window is being loaded. There is no need for a animation I just want to show a dialog.

    How to archieve this?


  • Moderators

    I have tried this many times and failed so far. You can have a go, if you want :) In theory, Loader has the "progress" property that can be used to get to know how it is doing. In practice, the property is not being updated too often - in my tests it went straight from 0 to 100%.

    For a dialog, you can also use Loader::status property.



  • I have tried the following:

    @
    Loader {
    id: loader
    source: "pretty_big.qml"
    onStatusChanged: if (status == Loader.Loading) console.log('Loading')
    @

    Guess what: I don't get the Loader.Loading status (no console log seen)....



  • I read this at QML Loader documentation:

    Note that if the source is a local file, the status will initially be Ready (or Error). While there will be no onStatusChanged signal in that case, the onLoaded will still be invoked.

    I am loading a local qml file, that's probably why I don't get the Loading event....


  • Moderators

    That is probably why I couldn't get it to work, too.

    Just a random thought, but that would be a massive overkill: maybe if you specified the path relative to localhost ("127.0.0.1/myQml.qml") it would fool the Loader into thinking it's a remote file. But that seems just crazy :) It would probably be better to just request this feature from Trolls, or implement ourselves and commit to main qt-project.org.



  • Currently I give the loader a trigger when it should load the QML file:

    @
    Loader {
    source: mycppObj.visible ? "pretty_big.qml" : ""
    }
    @

    Maybe I can somehow first trigger a wait dialog and then trigger the loader to load the qml. When the Loader is READY I hide the wait dialog.

    This all sounds very hackish..... Any suggestions how to do this?


  • Moderators

    @
    Loader {
    function loadFile() // or even better, pass the filename here
    {
    loadingScreen.visible = true;
    loader.loadMe = true;
    }

    property bool loadMe: false
    id: loader
    source: loadMe ? "pretty_big.qml" : ""

    onStatusChanged: if (status == Loader.Ready) loadingScreen.visible = false;
    }

    Rectangle {
    id: loadingScreen
    visible: false
    }
    @

    OK, that's just a quick draft. I have not thought it through, nor tested. Proceed with care :)


  • Moderators

    I did something similar by following this "wiki page ":http://www.developer.nokia.com/Community/Wiki/Implementing_a_Splash_Screen_with_Qt_Quick

    I hope it can help you too.



  • You mean I need to call the function to load the file and show the splashscreen? I use cpp object and qml property binding to show and hide the window.

    I have a lot (25) windows, so also 25 loaders. I also bind properties of cpp object and qml properties:

    @
    Loader {
    id: loader
    source: myCppObject.visible ? "window.qml" : ""
    Binding { target: loader.item; property: "title"; value: myCppObject.text }
    }
    @

    I think the code will be very ugly if I also put in some function to show a wait dialog.

    [quote author="sierdzio" date="1339774864"]@
    Loader {
    function loadFile() // or even better, pass the filename here
    {
    loadingScreen.visible = true;
    loader.loadMe = true;
    }

    property bool loadMe: false
    id: loader
    source: loadMe ? "pretty_big.qml" : ""

    onStatusChanged: if (status == Loader.Ready) loadingScreen.visible = false;
    }

    Rectangle {
    id: loadingScreen
    visible: false
    }
    @

    OK, that's just a quick draft. I have not thought it through, nor tested. Proceed with care :)[/quote]



  • I could use timers... Too bad QtQuick doesn't offer some handy stuff to do something simple like showing a wait dialog...

    I'll look into it.

    [quote author="Eddy" date="1339783207"]I did something similar by following this "wiki page ":http://www.developer.nokia.com/Community/Wiki/Implementing_a_Splash_Screen_with_Qt_Quick

    I hope it can help you too.[/quote]


  • Moderators

    [quote author="bkamps" date="1339785531"]Too bad QtQuick doesn't offer some handy stuff to do something simple like showing a wait dialog...
    [/quote]

    Well, with QML still being relatively new, you will have to wait for it (pun very much intended :P). Right now QML consists mostly of the basic building blocks. You are free to take it anywhere, but you have to do the "taking" yourself. Or look into some material from other people, like the desktop components, etc. Over time number of available components and add-ons will grow (if there is enough interest in QML).


Log in to reply
 

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