简体   繁体   English

没有QNetworkConfiguration虽然我可以连接到WIFI

[英]No QNetworkConfiguration although I can connect to WIFI

On my Laptop (Qt 5.11, Win10 x64) I am connected via WIFI, Qt https connections work. 在我的笔记本电脑上(Qt 5.11,Win10 x64)我通过WIFI连接,Qt https连接工作。 I wonder why I do not see any active network configurations, but can create HTTP requests. 我想知道为什么我没有看到任何活动的网络配置,但可以创建HTTP请求。 Also m_networkConfigManager->isOnline() is always false . 此外, m_networkConfigManager->isOnline()始终为false Am I missing something, or is this just a Qt bug? 我错过了什么,或者这只是一个Qt错误?

// 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. 我看到onNetworkConfigurationsUpdateCompleted被调用3次,然后每隔10秒定时调用一次。
  • after I init m_networkConfigManager I call m_networkConfigManager->updateConfigurations(); 在我初始化m_networkConfigManager我调用m_networkConfigManager->updateConfigurations();

--- edit 2 --- ---编辑2 ---

This version yields the same result (false) (not Queued) 此版本产生相同的结果(false)(未排队)

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 --- ---编辑3 ---

Follow up question: Disable Qt bearer management at runtime 后续问题: 在运行时禁用Qt承载管理

As of the Qt bug tracking system most likely a Qt bug. 截至Qt bug跟踪系统很可能是一个Qt bug。 The whole bearer system seems to be broken for WIFI, or at least being not very reliable. 对于WIFI来说,整个承载系统似乎已被破坏,或者至少不是非常可靠。 It is a bit hard to trace since there are different issues in different Qt versions depending on the platform (OS). 由于根据平台(OS)在不同的Qt版本中存在不同的问题,因此有点难以跟踪。

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. 在这种情况下,我只是将QAM设置为Accessible并通过http请求进行测试。 If it works WIFI is available. 如果它工作WIFI是可用的。

const QList<QNetworkConfiguration> allConfigurations = m_networkConfigManager->allConfigurations();
if (allConfigurations.isEmpty()) {
    m_accessManager->setNetworkAccessible(QNetworkAccessManager::Accessible);`
    .... test Qt http request ....     
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM