summaryrefslogtreecommitdiffstats
path: root/examples/wifi/wifi-qml/doc/src/wifi-qml.qdoc
blob: ba77c1e82992f1497b2978bc995240a05c980302 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc
** All rights reserved.
** For any questions to Digia, please use the contact form at
** http://www.qt.io
**
** This file is part of Qt Enterprise Embedded.
**
** Licensees holding valid Qt Enterprise licenses may use this file in
** accordance with the Qt Enterprise License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** the contact form at http://www.qt.io
**
****************************************************************************/
/*!

    \title Getting Started with B2Qt.Wifi in QML
    \example wifi/wifi-qml
    \ingroup wifi-examples
    \brief Guide to getting started with B2Qt.Wifi using QML.

    \section1 Preparing the Application

    Use the following \c import statement in the QML files to access the B2Qt.Wifi QML types:

    \code
    import B2Qt.Wifi 1.0
    \endcode

    This guide will demonstrate how to create a QML based application that utilizes
    B2Qt.Wifi API to set up a wifi network connection. We will start by looking at how to scan the
    surroundings for wifi access points and how to display and process this data in the application.
    At the end of the guide we will show how to connect directly to a known wifi network configuration.

    \image wifi-qml.jpg

    \section1 Listing Wifi Networks

    First we need to set up ListView which we will use to list wifi networks
    that can be sensed by the device. The sensed network access points are packed as a list-based
    data model and can be retrieved from WifiManager::networks. Here we also set a custom item
    delegate and connect to WifiManager::networkStateChanged signal.

    \snippet wifi/wifi-qml/WifiScanner.qml 0

    \section1 Creating a Delegate

    The wifi network model has many data roles that describe the different properties of wifi networks.
    This data can be used by an application to list detailed network information and/or to set up
    WifiConfiguration objects. We use these network data roles in our delegate for listing
    ssid, bssid, supported security protocols and for signal strengh representation.

    \snippet wifi/wifi-qml/WifiScanner.qml 1

    \section1 Connecting To a Selected Network

    WifiConfiguration element will be used to describe the network that we want to connect to,
    selected from the network list.

    \snippet wifi/wifi-qml/WifiScanner.qml 2

    When \uicontrol Connect button is clicked we set the network name and password properties on
    the \c config and pass it to WifiManager::connect, which sets up a wifi connection behind-the-scenes.
    During this operation or whenever there are changes in the network state, QWifiManager provides
    asynchronous QWifiManager::NetworkState change events.

    \snippet wifi/wifi-qml/WifiScanner.qml 3

    \section1 Connecting To a Known Network

    If you are not interested in scanning the environment for wifi network access points and you already
    know the network configuration beforehand, the network scanning, listing and selection steps can be
    entirely skipped. This can be a valid use-case for devices that won't be changing their physical location.

    QWifiManager::BackendState change events are delivered asynchronously. Therefore we have to add a signal handler
    that will connect to the network access point after the backend initialization process has been completed,
    if the backend is not already in the initialized state at the time of running this code.

    \snippet wifi/wifi-qml/WifiConnectionHandler.qml 0

 */