Qt Device Utilities WiFi Tutorial
Importing NetworkSettings
Import the NetworkSettings module as follows:
import QtDeviceUtilities.NetworkSettings
Filtering WiFi Networks
In order to connect to WiFi instead of wired networks, set NetworkSettingsManager in a WiFi filtering mode:
Component.onCompleted: NetworkSettingsManager.services.type = NetworkSettingsType.Wifi;
After you have set the filter, NetworkSettingsManager.services contains the NetworkService objects services representing WiFi networks.
Connecting to WiFi
In order to connect to Wifi, invoke the connectService method on NetworkService.
If no passphrase is needed, connectService connects to a WiFi network and changes the connected property of the selected service.
If a passphrase is needed, NetworkSettingsManager.userAgent emits the showUserCredentialsInput signal. Before a WiFi network is connected, you must provide the passphrase via NetworkSettingsManager.userAgent.setPassPhrase.
To implement the passphrase handling, you must set a signal handler as follows:
Connections { target: NetworkSettingsManager.userAgent onShowUserCredentialsInput : { // obtain the passphrase and set it } onError: { // handle errors } }
Implementing User Interface
When you are implementing a user interface for handling WiFi connections, remember that NetworkSettingsManager.services is designed to be used as a model. The Settings UI implementation uses it directly to display a list of available WiFi networks.
Handling WiFi connections and passphrases for list selections should be straightforward as described in Filtering WiFi Networks and Connecting to WiFi.
© 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.