How to listen internet connection.



  • Hi All,

    Do you know are there any way to trigger event network disable or enable?

    I am doing like this:

    networkConfigManager = new QNetworkConfigurationManager();

    //for MAC
    connect(networkConfigManager, SIGNAL(onlineStateChanged(bool)), this, SLOT(onlineStateChanged(bool)));

    //for windows
    connect(networkConfigManager,SIGNAL(configurationChanged(QNetworkConfiguration)), this, SLOT(networkConfigurationChanged()));

    I don't know why "onlineStateChanged" not working on Windows. I have to use "configurationChanged" as you can see. However, it is not working as expected in case i have some virtual machine network. When i disable/enable internet the events were not fired.

    Could someone help me on this?

    Thank you!


  • Moderators

    @William.Tran
    QNetworkAccessManager also has a networkAccessibleChanged() signal
    Maybe this works out better for you.



  • Thank you for your supporting. However, i could not get networkAccessibleChanged signal working as expected. my script is below:

    foreach(QNetworkConfiguration cfg, networkConfigManager->allConfigurations()){
    //if(cfg.name() == "Ethernet 6"){
    QNetworkAccessManager *accessManager = new QNetworkAccessManager();
    accessManager->setConfiguration(cfg);
    qDebug() << cfg.name() << accessManager->networkAccessible();
    connect(accessManager, SIGNAL(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)), this, SLOT(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)));
    //}
    }



  • This post is deleted!

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.