Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 Support (Qt 5) › Issue with WebStorage callback

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #16319

    Kool

    Hi All,

    The WebStorage does not seem to call the callback provided as a parameter. Could it be an issue with how I provide the function callback as a parameter?

    Minimal example:

    import Felgo 3.0
    import QtQuick 2.0
    
    GameWindow {
        id: gameWindow
        activeScene: scene
        screenWidth: 960
        screenHeight: 640
    
        Scene {
            id: scene
    
            width: 480
            height: 320
    
            WebStorage {
                id: storage
            }
    
            function theCallback() {
                console.debug("Called back")
            }
        }
    
    
        Component.onCompleted: {
            storage.setValue("someValue", 0.0, scene.theCallback)
            console.debug("someValue", storage.getValue("someValue"))
        }
    }
    

     

    #16323

    Günther
    Felgo Team

    Hi,

    we just had a closer look:
    Unfortunately the callback feature of setValue is broken at the moment – we will provide a fix with one of the next Felgo updates!

    Thanks for reporting the issue!

    Best,
    GT

    #16324

    Kool

    Hi Gunther,
    Thanks for looking into it. Could you suggest a work around to the following problem:

    • In my main menu scene, I have a ListView with a ListModel that shows level meta data such as “performance score” , “unlocked”, “completed”
    • The ListModel initialises with default values for all – but these values are updated with data from WebStorage
    • After the user completes a level, GameScene updates the level meta data in WebStorage
    • I needed the callback to refresh the ListModel above with the new WebStorage data

    Here is a minimal example:

    import Felgo 3.0
    import QtQuick 2.0
    
    GameWindow {
        id: gameWindow
        activeScene: scene
        screenWidth: 960
        screenHeight: 640
    
        Scene {
            id: scene
    
            width: 480
            height: 320
    
            WebStorage {
                id: storage
            }
    
            ListModel {
                id: model
                ListElement {name: "Level 1"; value: 50}
            }
    
            ListView {
                anchors.centerIn: parent
                model: model
                delegate: Item {
                    width: parent.width
                    height: 50
    
                    Text {
                        anchors.centerIn: parent
                        text: value
                    }
                }
            }
    
            function updateModel() {
                for (var ii = 0; ii < model.count; ++ii)
                {
                    var name = model.get(ii).name
                    var score = storage.getValue(name)
                    model.setProperty(ii, "value", score)
                }
            }
    
            Component.onCompleted: updateModel() // update model with storage data as soon as possible
        }
    
        Component.onCompleted: {
            // this actually takes place in my GameScene after a level finishes
            // and I simulate this here
    
            storage.setValue("Level 1", 50, scene.updateModel)
        }
    }

     

    (it might not compile/run – I wrote this in a text editor as I don’t have QtCreator on hand)

    As the callback mechanism doesn’t work, the model does not get updated. Is there a work around and hopefully better way to keep the ListModel and WebStorage in sync?

    #16326

    Christian
    Felgo Team

    Hi,

    the stored value is available immediatelly after you call setValue(), so you don’t need a callback for updating the model.

    If there is a write conflict (which only happens if the same key is written to from another device of the same user, you can use the onWriteConflict signal handler. You can also use the onWriteValueFinished signal handler, but it usually is better to immediatelly update your model after a setValue call, so users see the changed value immediatelly.

    Cheers, Chris

Viewing 4 posts - 1 through 4 (of 4 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded