Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-139604

Allow reading initial state via QNetworkInformation

XMLWordPrintable

    • Icon: Suggestion Suggestion
    • Resolution: Unresolved
    • Icon: Not Evaluated Not Evaluated
    • None
    • 6.9.1
    • Network
    • None
    • Android

      When using QNetworkInformation under Android not all values are initially populated and there seems to be no good way of knowing when the values of QNetworkInformation are populated.

      My use case is an app that has an Android service which needs to make a decision on startup based on QNetworkInformation::isMetered(). The problem is that at least this particular value doesn't seem to be initially populated. So if the network connection is metered when the service is started QNetworkInformation::isMetered() nevertheless initially returns false.

      If I postpone the decision after the event loop had a chance to run QNetworkInformation::isMetered() still returns false.

      If I postpone the decision to one second after the startup (using QTimer) QNetworkInformation::isMetered() returns true as it is supposed to. So it simply takes a short amount of time until the initialization is done. Postponing the decision by a fixed amount of "sleep time" is of course needlessly delaying the service startup and also introduces a race condition.

      So I thought maybe I'll just postpone the decision on the first isMeteredChanged() signal. This works for the so far considered case that the connection is initially metered. However, if it is not initially metered the signal is never emitted so the code using isMetered() never runs and the service startup never concludes.

      With that I think I'm out of options. So it would be great if QNetworkInformation would be initialized from the start. If that's not possible it would be great if QNetworkInformation would emit its signals as soon as it is initialized in any case (so also when e.g. isMetered() is false). This way one could at least easily wait for it to be initialized.

      It would also be good if QNetworkInformation could generally tell whether its fields are initialized (and not just whether they are generally supported).

      Note that this limitation can actually be easily worked around under Android by implementing the initial lookup in Java, e.g. https://github.com/Martchus/syncthingtray/commit/46995a4f19086e33f516d2af1517a6ce2fbfaf74#diff-2308da248536148b24d34659668f35579b50ddf4e2b56b71ee628dfebf51ef9eR335. It would nevertheless be great if one could entirely rely on Qt for this. Besides, I am not sure whether the limitation is only present under Android and having to add platform-specific code like this for multiple platforms would not be nice.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            manordheim MÃ¥rten Nordheim
            martchus martchus
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes