Gatis Paeglis

Qt Weekly #27: WiFi networking support on embedded devices

Published Monday February 23rd, 2015
6 Comments on Qt Weekly #27: WiFi networking support on embedded devices
Posted in Embedded, Network

As a part of the Qt for Device Creation offering we provide several
helpful add-on modules that assist in creating applications for embedded devices. In this blog post I would like to demonstrate some of the features supported by the B2Qt WiFi add-on module.

What is it?

The B2Qt WiFi module provides APIs for connecting embedded devices to a wireless network. There are C++ and QML APIs available for managing wireless network connectivity, scanning for wireless network access points, retrieving information from these access points, monitoring for network state changes and more. The API allows you to manage when and to which network to connect, and when to go offline.

Overview of the API

The module consists of 3 classes:

  • (Q)WifiConfiguration – Used to define a network configuration.
  • (Q)WifiDevice – Represents a physical device.
  • (Q)WifiManager – Main interface to the WiFi functionality (Singleton).

How to use it

Here is a code snippet in QML demonstrating how easy it is to connect a device to a wireless access point named “bus-station-wifi” that uses the WPA2 security protocol:

    import B2Qt.Wifi 1.0

    WifiConfiguration {
        id: localConfig
        ssid: "bus-station-wifi"
        passphrase: "mypassword"
        protocol: "WPA2"

    Connections {
        target: WifiManager
        onBackendStateChanged: {
            if (WifiManager.backendState === WifiManager.Running)
        onNetworkStateChanged: {
            if (WifiManager.networkState === WifiManager.Connected)
                print("successfully connected to: " + WifiManager.currentSSID)

    Component.onCompleted: {
        if (WifiManager.backendState === WifiManager.Running) {
        } else {
            // starts initialization of wifi backend

And the following code illustrates how to achieve the same in C++:

class WifiConnectionHandler : public QObject

        m_manager = QWifiManager::instance();
        connect(m_manager, &QWifiManager::backendStateChanged,
                this, &WifiConnectionHandler::handleBackendStateChanged);

        if (m_manager->backendState() == QWifiManager::Running) {
        } else {

protected slots:
    void handleBackendStateChanged(QWifiManager::BackendState state)
        if (state == QWifiManager::Running)

    QWifiManager *m_manager;
    QWifiConfiguration m_config;

The previous examples showed how to connect to a network for which the configuration is known beforehand. As mentioned earlier, the WiFi module can also be used to scan for available WiFi access points. In the next example we use the scan results and present them in a list where the user can select which network to use.

    Binding {
        target: WifiManager
        property: "scanning"
        value: WifiManager.backendState === WifiManager.Running

    WifiConfiguration { id: config }
    ListView {
        anchors.fill: parent
        spacing: 8
        model: WifiManager.networks
        delegate: Row {
            spacing: 10
            Text { text: ssid }
            TextField { id: passwordInput }
            Button {
                text: "connect"
                onClicked: {
                    config.ssid = ssid;
                    config.passphrase = passwordInput.text

Here you can see a screenshot of a more advanced application running on a Nitrogen6_MAX board that utilizes WiFi API for wireless network setup.


For more information check out the documentation.

Do you like this? Share it
Share on LinkedInGoogle+Share on FacebookTweet about this on Twitter

Posted in Embedded, Network


Markus Stainer says:

Does the B2Qt WiFi module has Wifi Direct support between devices? Or manage a connection just to an AP?

Gatis Paeglis Gatis Paeglis says:

There is no Qt API for Wi-Fi Direct. The backend has support for it so API can be added in future releases if there will be interest. B2Qt WiFi 1.0 operates in infrastructure mode that requires a central access point.

qq says:

I have a portable wi-fi flash drive. it is Wifi Direct. what function should I use? I want to connect to the storage at first. And then, I want to upoad file to the storage.

Gatis Paeglis Gatis Paeglis says:

From your other comment in the “Qt 5.4.1 Released” blog post I see that you are trying to do this on Android and iOS. B2Qt.Wifi is for embedded device creation

If you want to connect Android/iOS programmatically to the USB flash drive then on Android you would need to use native API (Java) – see on iOS as far as I know there is no public API for WiFi functionality.
Or you can connect your devices manually by using system settings in Android/iOS and then use Qt APIs to transer data – see

qq says:

Yes,I am trying to use QTcpSocket. It is not working in my code. I never use those functions before. I will try to correct my code. But Does it is possible to connect the drive by qt? (QTcpSocket,QUdpSocket or Bearer Management)

Alessandro says:


I am interested in the WiFi api for iOS/Android as tethering to connect to Arduino and as I understood I can achieve this by calling native API to then bridge to the WiFi api correct? Any example?

Commenting closed.

Get started today with Qt Download now