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. Problem with Qt Quick app reconnecting to network after disconnecting

Problem with Qt Quick app reconnecting to network after disconnecting

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 1.6k Views 1 Watching
  • 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.
  • Q Offline
    Q Offline
    QtQueries
    wrote on last edited by
    #1

    Hi all

    My app uses XMLHttpRequests within Javascript to connect to a web service.

    The problem we are having is that when the handset loses connectivity and then finds it again, we are unable to make any more successful requests.

    Also, we use the Qt Mobility Map object. After losing then regaining connectivity, the Map can no longer display any tiles either.

    Here's an example to illustrate the problem

    main.qml
    Code:
    @import QtQuick 1.0
    import "NetTest.js" as JS

    Rectangle {
    id: screen
    width: 360
    height: 360
    Column {
    anchors.centerIn: parent
    Text {
    text: "Callbacks: 0"
    id: callbacks
    }

        Text {
            text: "Errors: 0"
            id: errors
        }
    }
    
    Timer {
        running: true
        repeat: true
        interval: 10000
        onTriggered: {
            console.log("Net test request");
            JS.request(screen.callback, screen.errback)
        }
    }
    
    MouseArea {
        anchors.fill: parent
        onClicked: {
            Qt.quit();
        }
    }
    
    function callback() {
        JS.numCallbacks++
        callbacks.text = "Callbacks: " + JS.numCallbacks
    }
    
    function errback() {
        JS.numErrors++
        errors.text = "Errors: " + JS.numErrors
    }
    

    }@
    NetTest.js
    Code:
    @var numCallbacks = 0
    var numErrors = 0

    function request(callback, errback) {
    var xhr = new XMLHttpRequest();
    xhr.open("GET", "http://www.google.co.uk", true);
    xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    xhr.setRequestHeader("Data-Type", "json");
    xhr.onreadystatechange = function () {
    console.log("Ready state: " + xhr.readyState)
    console.log("Resp text: " + xhr.responseText)
    console.log("Status: " + xhr.status)
    if (xhr.readyState == xhr.DONE) {
    try {
    if (xhr.status != 200 && typeof errback !== 'undefined') {
    errback();
    } else if (typeof callback !== 'undefined') {
    callback();
    }
    } catch (err) {
    console.log("GetTraffic err: " + err);
    if (typeof errback !== 'undefined') {
    errback();
    }
    }
    }
    }

    xhr.send();
    

    }@

    1. run app
    2. observe Callbacks incrementing every 10 seconds
    3. Press power button, select Offline mode
    4. observe Errors incrementing every 10 seconds
    5. Press power button, select General mode

    Actual: Errors continues to increment every 10 seconds
    Expected: Callbacks increments every 10 seconds

    How can we make the app reconnect again?

    The problem doesn't happen on the Qt simulator, but it does on the N8.

    Thanks

    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