From 03b3e6fd62ff9e9a80212a313340e0a0c2f0135f Mon Sep 17 00:00:00 2001 From: Ville Voutilainen Date: Mon, 4 Sep 2017 11:55:21 +0300 Subject: Add a wifi example The WiFi tutorial linked to NetworkSettings module and NetworkSettingsManager QML type. Added a section Tutorial and Example Code to a module reference page. It contains a link to WiFi tutorial and provides the Settings UI Git repository as an additional example code for Qt Device Utilities. Task-number: QTBUG-56694 Change-Id: Ib6c6a446fd36530525d521e5d568ec154d58a63d Reviewed-by: Leena Miettinen Reviewed-by: Teemu Holappa --- src/doc/src/external-resources.qdoc | 11 ++++- src/doc/src/qtdeviceutilities.qdoc | 16 ++++++- src/doc/src/wifiexample.qdoc | 78 ++++++++++++++++++++++++++++++++++ src/imports/networksettings/plugin.cpp | 6 +++ 4 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 src/doc/src/wifiexample.qdoc (limited to 'src') diff --git a/src/doc/src/external-resources.qdoc b/src/doc/src/external-resources.qdoc index 9914ad3..2edf436 100644 --- a/src/doc/src/external-resources.qdoc +++ b/src/doc/src/external-resources.qdoc @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** All rights reserved. ** For any questions to The Qt Company, please use the contact form at ** http://www.qt.io/contact-us @@ -20,3 +20,12 @@ \title Qt for Device Creation */ +/*! + \externalpage http://code.qt.io/cgit/qt/qtdeviceutilities.git/ + \title Device Utilities Git Repository +*/ + +/*! + \externalpage http://code.qt.io/cgit/qt/qtdeviceutilities.git/tree/src/settingsui + \title Settings UI +*/ diff --git a/src/doc/src/qtdeviceutilities.qdoc b/src/doc/src/qtdeviceutilities.qdoc index bce13a8..9e692fe 100644 --- a/src/doc/src/qtdeviceutilities.qdoc +++ b/src/doc/src/qtdeviceutilities.qdoc @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** All rights reserved. ** For any questions to The Qt Company, please use the contact form at ** http://www.qt.io/contact-us @@ -48,5 +48,19 @@ \section2 Settings UI \generatelist qmltypesbymodule QtDeviceUtilities.SettingsUI + + \section1 Tutorial and Example Code + + \l{Qt Device Utilities WiFi Tutorial} demonstrates how you can use + the \l{QtDeviceUtilities.NetworkSettings}{NetworkSettings} module for + connecting to WiFi. + + The source code of Qt Device Utilities is availabe via a public Git repository. + For more information, see \l{Device Utilities Git Repository}. + + You find the Qt Device Utilities module sources under + \l{http://code.qt.io/cgit/qt/qtdeviceutilities.git/tree/src}. Especially, + the sources of \l{Settings UI} provide examples of how to use Qt Device Utilities. + */ diff --git a/src/doc/src/wifiexample.qdoc b/src/doc/src/wifiexample.qdoc new file mode 100644 index 0000000..6e28099 --- /dev/null +++ b/src/doc/src/wifiexample.qdoc @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** All rights reserved. +** For any questions to The Qt Company, please use the contact form at +** http://www.qt.io/contact-us +** +** This file is part of Qt for Device Creation. +** +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +****************************************************************************/ +/*! + \page qtdeviceutilities-wifitutorial.html + \title Qt Device Utilities WiFi Tutorial + \previouspage qtee-module-reference.html + + \section1 Importing NetworkSettings + + Import the NetworkSettings module as follows: + \badcode + import QtDeviceUtilities.NetworkSettings 1.0 + \endcode + + \section1 Filtering WiFi Networks + + In order to connect to WiFi instead of wired networks, set + NetworkSettingsManager in a WiFi filtering mode: + + \badcode + Component.onCompleted: NetworkSettingsManager.services.type = NetworkSettingsType.Wifi; + \endcode + + After you have set the filter, \l{NetworkSettingsManager::services}{NetworkSettingsManager.services} contains + the NetworkService objects services representing WiFi networks. + + \section1 Connecting to WiFi + + In order to connect to Wifi, invoke the + \l{NetworkService::connectService()}{connectService} method on NetworkService. + + If no passphrase is needed, \l{NetworkService::connectService()}{connectService} + connects to a WiFi network and changes the connected property of the selected service. + + If a passphrase is needed, NetworkSettingsManager.userAgent + emits the \l{NetworkSettingsManager::userAgent.showUserCredentialsInput}{showUserCredentialsInput} signal. + Before a WiFi network is connected, you must provide the passphrase via + \l{NetworkSettingsManager::userAgent.setPassphrase}{NetworkSettingsManager.userAgent.setPassPhrase}. + + To implement the passphrase handling, you must set a signal handler as follows: + \badcode + Connections { + target: NetworkSettingsManager.userAgent + onShowUserCredentialsInput : { + // obtain the passphrase and set it + } + onError: { + // handle errors + } + } + \endcode + + \section1 Implementing User Interface + + When you are implementing a user interface for handling WiFi connections, + remember that \l{NetworkSettingsManager::services}{NetworkSettingsManager.services} + is designed to be used as a model. The \l{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 \l{Filtering WiFi Networks} and + \l{Connecting to WiFi}. +*/ diff --git a/src/imports/networksettings/plugin.cpp b/src/imports/networksettings/plugin.cpp index 2a67657..665cb6a 100644 --- a/src/imports/networksettings/plugin.cpp +++ b/src/imports/networksettings/plugin.cpp @@ -54,6 +54,9 @@ import QtDeviceUtilities.NetworkSettings 1.0 \endcode + \l{Qt Device Utilities WiFi Tutorial} demonstrates how you can use + \l{QtDeviceUtilities.NetworkSettings}{NetworkSettings} for connecting to WiFi. + \note Some functions may not be available on all of the platforms. \section1 QML Types @@ -66,6 +69,9 @@ There is no need to create an instance of this object. To use it, simply import the \c {QtDeviceUtilities.NetworkSettings} module. + + \l{Qt Device Utilities WiFi Tutorial} demonstrates how you can use + \l{NetworkSettingsManager} for connecting to WiFi. */ /*! -- cgit v1.2.3