QNetworkSettingsManager Class

The QNetworkSettingsManager class provides an asynchronous API to network settings. More...

Header: #include <QNetworkSettingsManager>
qmake: QT += networksettings
Inherits: QObject

Properties

  • services : QNetworkSettingsServiceFilter* const
  • userAgent : QNetworkSettingsUserAgent* const

Public Functions

QNetworkSettingsManager(QObject *parent = nullptr)
void clearConnectionState()
void clearCurrentConnection(QNetworkSettingsService *service)
void connectBySsid(const QString &name, const QString &passphrase)
QNetworkSettingsService *currentWifiConnection()
QNetworkSettingsService *currentWiredConnection()
QNetworkSettingsInterface *interface(int type, int instance)
QNetworkSettingsInterfaceModel *interfaces()
QNetworkSettingsService *service(const QString &name, int type)
QNetworkSettingsServiceFilter *services()
void setCurrentConnection(QNetworkSettingsService *service)
void setUserAgent(QNetworkSettingsUserAgent *agent)
void tryNextConnection()
QNetworkSettingsUserAgent *userAgent()

Signals

Detailed Description

The network manager is designed to be used as a model that contains lists of available network interfaces and services.

A delegate in a view that uses the interface model can access the network interface item with the data model role.

The services list in the model can be controlled with the QNetworkSettingsType::type property, and network service items can be retrieved with the QNetworkSettingsServiceFilter::itemFromRow() method.

The following code demonstrates how you initialize the network manager:

manager = new QNetworkSettingsManager(this);
QObject::connect(manager, &QNetworkSettingsManager::interfacesChanged,
    this, &MainWindow::interfacesChanged);

QObject::connect(manager, &QNetworkSettingsManager::servicesChanged,
    this, &MainWindow::servicesChanged);

After initializing the network manager, you can iterate WiFi SSIDs as follows:

void WifiHandler::servicesChanged()
{
    QList<QNetworkSettingsService*> services = qobject_cast<QNetworkSettingsServiceModel*>(manager->services()->sourceModel())->getModel();

    for (const auto &service : services) {
        qDebug() << service->name();
    }
}


void WifiHandler::interfacesChanged()
{
    QList<QNetworkSettingsInterface*> interfaces = manager->interfaces()->getModel();
    for (const auto &interface : interfaces) {
        if (interface->type() == QNetworkSettingsType::Type::Wifi) {
            if (interface->powered()) {
                interface->scanServices();
            } else {
            interface->setPowered(true);
            }
        }
    }
}

See also QNetworkSettingsService.

Property Documentation

[read-only] currentWifiConnection : QNetworkSettingsService* const

Holds the current Wifi connection.

Access functions:

QNetworkSettingsService *currentWifiConnection()

Notifier signal:

See also QNetworkSettingsService.

[read-only] currentWiredConnection : QNetworkSettingsService* const

Holds the current wired connection.

Access functions:

QNetworkSettingsService *currentWiredConnection()

Notifier signal:

See also QNetworkSettingsService.

[read-only] interfaces : QNetworkSettingsInterfaceModel* const

Holds the interface model.

Access functions:

QNetworkSettingsInterfaceModel *interfaces()

Notifier signal:

See also QNetworkSettingsInterfaceModel.

[read-only] services : QNetworkSettingsServiceFilter* const

Holds the service model.

Access functions:

QNetworkSettingsServiceFilter *services()

Notifier signal:

See also QNetworkSettingsServiceFilter.

[read-only] userAgent : QNetworkSettingsUserAgent* const

Holds the user credentials for connecting to a network.

Access functions:

QNetworkSettingsUserAgent *userAgent()

See also QNetworkSettingsUserAgent.

Member Function Documentation

[explicit] QNetworkSettingsManager::QNetworkSettingsManager(QObject *parent = nullptr)

Creates a network manager with the parent parent.

void QNetworkSettingsManager::clearConnectionState()

Clears the connection state.

void QNetworkSettingsManager::clearCurrentConnection(QNetworkSettingsService *service)

Terminates the current connection to the specified service.

[invokable] void QNetworkSettingsManager::connectBySsid(const QString &name, const QString &passphrase)

Creates a connection to the network specified by name using the password passphrase.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

QNetworkSettingsService *QNetworkSettingsManager::currentWifiConnection()

Returns the current Wifi connection.

Note: Getter function for property currentWifiConnection.

[signal] void QNetworkSettingsManager::currentWifiConnectionChanged()

This signal is emitted when the current Wifi connection changes.

Note: Notifier signal for property currentWifiConnection.

QNetworkSettingsService *QNetworkSettingsManager::currentWiredConnection()

Returns the current wired connection.

Note: Getter function for property currentWiredConnection.

[signal] void QNetworkSettingsManager::currentWiredConnectionChanged()

This signal is emitted when the current wired connection changes.

Note: Notifier signal for property currentWiredConnection.

[invokable] QNetworkSettingsInterface *QNetworkSettingsManager::interface(int type, int instance)

Returns the network interface instance instance of the type type.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

QNetworkSettingsInterfaceModel *QNetworkSettingsManager::interfaces()

Returns the interface model.

Note: Getter function for property interfaces.

[signal] void QNetworkSettingsManager::interfacesChanged()

This signal is emitted when the network interface changes.

Note: Notifier signal for property interfaces.

[invokable] QNetworkSettingsService *QNetworkSettingsManager::service(const QString &name, int type)

Returns the service model name of the type type.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

QNetworkSettingsServiceFilter *QNetworkSettingsManager::services()

Returns the service model.

QNetworkSettingsType::Type

Note: Getter function for property services.

[signal] void QNetworkSettingsManager::servicesChanged()

This signal is emitted when the network service changes.

Note: Notifier signal for property services.

void QNetworkSettingsManager::setCurrentConnection(QNetworkSettingsService *service)

Creates a connection to the specified service.

void QNetworkSettingsManager::setUserAgent(QNetworkSettingsUserAgent *agent)

Sets the user credentials for connecting to a network to agent.

See also userAgent().

void QNetworkSettingsManager::tryNextConnection()

Attempts to connect using the next network interface in the model.

QNetworkSettingsUserAgent *QNetworkSettingsManager::userAgent()

Returns the user credentials for connecting to a network.

Note: Getter function for property userAgent.

See also setUserAgent().

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.