QNetworkSettingsManager Class
The QNetworkSettingsManager class provides an asynchronous API to network settings. More...
Header: | #include <QNetworkSettingsManager> |
qmake: | QT += networksettings |
Inherits: | QObject |
Properties
|
Public Functions
QNetworkSettingsManager(QObject *parent = Q_NULLPTR) | |
void | clearConnectionState() |
void | clearCurrentConnection(QNetworkSettingsService *service) |
void | connectBySsid(const QString &name, const QString &passphrase) |
QNetworkSettingsService * | currentWifiConnection() |
QNetworkSettingsService * | currentWiredConnection() |
bool | hasUsbEthernetProtocolConfiguration() |
QNetworkSettingsInterface * | interface(int type, int instance) |
QNetworkSettingsInterfaceModel * | interfaces() |
QNetworkSettingsService * | service(const QString &name, int type) |
QNetworkSettingsServiceFilter * | services() |
void | setCurrentConnection(QNetworkSettingsService *service) |
void | setUsbVirtualEthernetLinkProtocol(const QString &protocol) |
void | setUserAgent(QNetworkSettingsUserAgent *agent) |
void | tryNextConnection() |
QString | usbEthernetInternetProtocolAddress() |
QString | usbVirtualEthernetLinkProtocol() |
QNetworkSettingsUserAgent * | userAgent() |
Signals
void | currentWifiConnectionChanged() |
void | currentWiredConnectionChanged() |
void | interfacesChanged() |
void | servicesChanged() |
void | usbEthernetInternetProtocolAddressChanged(const QString &newusbEthernetIpAddress) |
void | usbVirtualEthernetLinkProtocolChanged(const QString &newUsbEthernetProtocol) |
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::Types::Wifi) { if (interface->powered()) { interface->scanServices(); } else { interface->setPowered(true); } } } }
See also QNetworkSettingsService.
Property Documentation
currentWifiConnection : QNetworkSettingsService* const
Holds the current Wifi connection.
Access functions:
QNetworkSettingsService * | currentWifiConnection() |
Notifier signal:
void | currentWifiConnectionChanged() |
See also QNetworkSettingsService.
currentWiredConnection : QNetworkSettingsService* const
Holds the current wired connection.
Access functions:
QNetworkSettingsService * | currentWiredConnection() |
Notifier signal:
See also QNetworkSettingsService.
interfaces : QNetworkSettingsInterfaceModel* const
Holds the interface model.
Access functions:
QNetworkSettingsInterfaceModel * | interfaces() |
Notifier signal:
void | interfacesChanged() |
See also QNetworkSettingsInterfaceModel.
services : QNetworkSettingsServiceFilter* const
Holds the service model.
Access functions:
QNetworkSettingsServiceFilter * | services() |
Notifier signal:
void | servicesChanged() |
See also QNetworkSettingsServiceFilter.
userAgent : QNetworkSettingsUserAgent* const
Holds the user credentials for connecting to a network.
Access functions:
QNetworkSettingsUserAgent * | userAgent() |
See also QNetworkSettingsUserAgent.
Member Function Documentation
QNetworkSettingsManager::QNetworkSettingsManager(QObject *parent = Q_NULLPTR)
Creates a network manager with the parent parent.
[signal]
void QNetworkSettingsManager::currentWifiConnectionChanged()
This signal is emitted when the current Wifi connection changes.
Note: Notifier signal for property currentWifiConnection.
[signal]
void QNetworkSettingsManager::currentWiredConnectionChanged()
This signal is emitted when the current wired connection changes.
Note: Notifier signal for property currentWiredConnection.
[signal]
void QNetworkSettingsManager::interfacesChanged()
This signal is emitted when the network interface changes.
Note: Notifier signal for property interfaces.
[signal]
void QNetworkSettingsManager::servicesChanged()
This signal is emitted when the network service changes.
Note: Notifier signal for property services.
void QNetworkSettingsManager::clearConnectionState()
Clears the connection state.
void QNetworkSettingsManager::clearCurrentConnection(QNetworkSettingsService *service)
Terminates the current connection to the specified service.
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.
QNetworkSettingsService *QNetworkSettingsManager::currentWiredConnection()
Returns the current wired connection.
Note: Getter function for property currentWiredConnection.
bool QNetworkSettingsManager::hasUsbEthernetProtocolConfiguration()
Returns true if usb ethernet protocol is configured by file and configuration file exists.
Note: This function can be invoked via the meta-object system and from QML. See Q_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.
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.
Note: Getter function for property services.
void QNetworkSettingsManager::setCurrentConnection(QNetworkSettingsService *service)
Creates a connection to the specified service.
void QNetworkSettingsManager::setUsbVirtualEthernetLinkProtocol(const QString &protocol)
Set the usb ethernet protocol according to parameter.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
See also usbVirtualEthernetLinkProtocol().
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.
QString QNetworkSettingsManager::usbEthernetInternetProtocolAddress()
Returns the ip address of usb ethernet network.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
Note: Getter function for property usbEthernetIpAddress.
QString QNetworkSettingsManager::usbVirtualEthernetLinkProtocol()
Returns the usb ethernet protocol
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
Note: Getter function for property usbEthernetProtocol.
See also setUsbVirtualEthernetLinkProtocol().
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.