3

On my Laptop (Qt 5.11, Win10 x64) I am connected via WIFI, Qt https connections work. I wonder why I do not see any active network configurations, but can create HTTP requests. Also m_networkConfigManager->isOnline() is always false. Am I missing something, or is this just a Qt bug?

// signal / slot
connect(m_networkConfigManager, &QNetworkConfigurationManager::updateCompleted, this, &CApplication::onNetworkConfigurationsUpdateCompleted, Qt::QueuedConnection);

// called via signal
void CApplication::onNetworkConfigurationsUpdateCompleted()
{
    const QNetworkConfiguration config = m_networkConfigManager->defaultConfiguration();
    for (const QNetworkConfiguration &config : m_networkConfigManager->allConfigurations())
    {
        // never reached
        const QString cs = CNetworkUtils::toString(config);
        CLogMessage(this).info("Network config: %1") << cs;
    }

    // always false
    bool isOnline = m_networkConfigManager->isOnline();
    .... debug messages, I see onNetworkConfigurationsUpdateCompleted being called 3 times
    ....
}

--- edit ---

  • I see onNetworkConfigurationsUpdateCompleted being called 3 times and then somehow periodically every 10 secs.
  • after I init m_networkConfigManager I call m_networkConfigManager->updateConfigurations();

--- edit 2 ---

This version yields the same result (false) (not Queued)

connect(m_networkConfigManager, &QNetworkConfigurationManager::updateCompleted, [ = ]
{
   bool isOnline = m_networkConfigManager->isOnline();
   qDebug() << isOnline;
});

and this is never called

connect(m_networkConfigManager, &QNetworkConfigurationManager::onlineStateChanged, [](bool isOnline)
{
    qDebug() << isOnline; // never get here
});

--- edit 3 ---

Follow up question: Disable Qt bearer management at runtime

Horst Walter
  • 13,663
  • 32
  • 126
  • 228
  • 1
    May I suggest you to connect `QNetworkConfigurationManager::onlineStateChanged` to a slot/lambda with a debug message and see if it changes at all. – scopchanov Aug 04 '18 at 16:38
  • 1
    If the question is whether `onNetworkConfigurationsUpdateCompleted` is called, then YES, I can see it in the debugger being called 3-4 times, also I see my debug messages which are just now shown in the code segment above. Updated the question, thanks for the hint. – Horst Walter Aug 04 '18 at 16:51
  • Actually, my idea was more in the following direction: could `isOnline` become `true` for a short time and then go back to `false` by the time you query it? – scopchanov Aug 04 '18 at 16:55
  • 1
    updated the code above, onlineChanged actually never triggers something in my very scenario. btw, with a cable connection via LAN it works . – Horst Walter Aug 04 '18 at 17:24
  • 1
    To me it looks like you've done everything right, but it doesn't behave as expected. Maybe you should report it to Qt as a bug. – scopchanov Aug 05 '18 at 00:08

1 Answers1

1

As of the Qt bug tracking system most likely a Qt bug. The whole bearer system seems to be broken for WIFI, or at least being not very reliable. It is a bit hard to trace since there are different issues in different Qt versions depending on the platform (OS).

I am using a simple hack workaround (bad practice, but working). If there is no network configuration this could mean I run into that issue, or there is no network interface at all. In that very case I just set the QAM to Accessible and test via a http request. If it works WIFI is available.

const QList<QNetworkConfiguration> allConfigurations = m_networkConfigManager->allConfigurations();
if (allConfigurations.isEmpty()) {
    m_accessManager->setNetworkAccessible(QNetworkAccessManager::Accessible);`
    .... test Qt http request ....     
}
Horst Walter
  • 13,663
  • 32
  • 126
  • 228