Search code examples
qtwifiqml

setting static IP for wifi connection in QT


I am trying to create a QT based application that scan and connect WiFi networks. I am using this example as a reference code.

  1. Is it possible to assign static IP for the WiFi connection using QNetworkConfiguration or any related class ?
  2. How to authenticate the networks that are password protected ?

thanks in advance......

I have created a net work session using the below code set..

void BearerMonitor::createNewSessionFromQml(QString ssid)
{
    QList<QNetworkConfiguration> allConfigurations = manager.allConfigurations();
    while (!allConfigurations.isEmpty()) {
        QNetworkConfiguration config = allConfigurations.takeFirst();
        if(config.name()==ssid)
            createSessionFor(config);
    }
}

SessionWidget::SessionWidget(const QNetworkConfiguration &config, QObject *parent):QObject(parent)
    {
        session = new QNetworkSession(config, this);
        session->open();
}

Solution

  • No you can't. At least not with just Qt APIs.

    Please read this and in particular this. QNetworkConfiguration is just a facility to manage network configurations. Editing such configurations is demanded to native code / OS interactions. From the second link:

    Note that the QNetworkConfiguration object only provides limited information about the configuration details themselves. It's main purpose is to act as a configuration identifier through which link layer connections can be created, destroyed and monitored.

    Even the "start/stop network interfaces" claim is not entirely true since such a feature is available only in certain OSs (not the mobile ones). See the "Platform capabilities" section of the second link for more details about that.

    The same reasoning applies to the password question. Once a network is registed in the OS with the corresponding password (because of native code or the user physically registering it) a new configuration is available to the NetworkConfigurationManager, granted that the list of configurations is updated via updateConfigurations(). The new configuration contains the password but you can't edit it from Qt APIs.

    Native code is the only solution, as said. Still, Apple does not want you to mess up with WiFi programatically since private APIs for that cannot be used in iOS > 5.1 (the oldest version supported by Qt as for Qt 5.4).