How to set default access point using Qt Mobility APIs
(→Source File) |
hamishwillee
(Talk | contribs) m (Text replace - "<code cpp>" to "<code cpp-qt>") |
||
| (9 intermediate revisions by 4 users not shown) | |||
| Line 1: | Line 1: | ||
| − | [[ | + | {{ArticleMetaData <!-- v1.2 --> |
| + | |sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] --> | ||
| + | |installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | ||
| + | |devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') --> | ||
| + | |sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) --> | ||
| + | |platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later --> | ||
| + | |devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) --> | ||
| + | |dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 --> | ||
| + | |signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer --> | ||
| + | |capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. --> | ||
| + | |keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase --> | ||
| + | |language= <!-- Language category code for non-English topics - e.g. Lang-Chinese --> | ||
| + | |translated-by= <!-- [[User:XXXX]] --> | ||
| + | |translated-from-title= <!-- Title only --> | ||
| + | |translated-from-id= <!-- Id of translated revision --> | ||
| + | |review-by= <!-- After re-review: [[User:username]] --> | ||
| + | |review-timestamp= <!-- After re-review: YYYYMMDD --> | ||
| + | |update-by= <!-- After significant update: [[User:username]]--> | ||
| + | |update-timestamp= <!-- After significant update: YYYYMMDD --> | ||
| + | |creationdate= 20100329 | ||
| + | |author= [[User:Gaba88]] | ||
| + | }} | ||
| + | [[Category:Qt Mobility]] | ||
{|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0" | {|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0" | ||
|- | |- | ||
| Line 8: | Line 30: | ||
|'''Tested on devices''' || Nokia N97 | |'''Tested on devices''' || Nokia N97 | ||
|- | |- | ||
| − | |'''Category''' || Qt | + | |'''Category''' || Qt |
|'''Subcategory''' || Qt Mobility API | |'''Subcategory''' || Qt Mobility API | ||
|- | |- | ||
| Line 20: | Line 42: | ||
| − | {{Tip| Read this article before moving forward: [[Setting up environment for Qt Mobility API]]}} | + | {{Tip| Read this article before moving forward: [[Archived:Setting up environment for Qt Mobility API]]}} |
| Line 26: | Line 48: | ||
=Overview= | =Overview= | ||
| − | + | {{Abstract|This article demonstrate how to set default access point using the [http://doc.qt.nokia.com/qtmobility-1.2/bearer-management.html Bearer Management APIs] of the [http://doc.qt.nokia.com/qtmobility-1.2/ Qt's Mobility] Package.}} | |
=Project Configuration File (.pro file)= | =Project Configuration File (.pro file)= | ||
| − | + | Add the Qt Mobility project configuration option in the '''.Pro''' file as shown below | |
<code> | <code> | ||
CONFIG += mobility | CONFIG += mobility | ||
| Line 39: | Line 61: | ||
=Header File= | =Header File= | ||
| − | + | Also do add the Qt mobility name space before using any Qt mobility APIs, | |
| + | <code cpp-qt> | ||
QTM_USE_NAMESPACE | QTM_USE_NAMESPACE | ||
| + | </code> | ||
| + | Declare a [http://doc.qt.nokia.com/4.7/qnetworksession.html QNetworkSession] object in the header file which will help in opening the network connections. | ||
| − | + | <code cpp-qt> | |
| − | + | ||
| − | <code cpp> | + | |
#include <qmobilityglobal.h> | #include <qmobilityglobal.h> | ||
| Line 55: | Line 78: | ||
=Source File= | =Source File= | ||
| − | + | After declaring the [http://doc.qt.nokia.com/4.7/qnetworksession.html QNetworkSession] object we need to use the [http://doc.qt.nokia.com/4.7/qnetworkconfigurationmanager.html QNetworkConfigurationManager] and [http://doc.qt.nokia.com/4.7/qnetworkconfiguration.html QNetworkConfiguration] class to ask the user about the access point and make that as a default connection. | |
A sample function is shown below : | A sample function is shown below : | ||
| − | <code cpp> | + | <code cpp-qt> |
QNetworkConfigurationManager manager; | QNetworkConfigurationManager manager; | ||
| Line 76: | Line 99: | ||
</code> | </code> | ||
| − | It is worth noting that QNetworkConfigurationManager::defaultConfiguration() reflects the device's default connection setting, which can be controlled from the UI. | + | It is worth noting that {{Icode|QNetworkConfigurationManager::defaultConfiguration()}} reflects the device's default connection setting, which can be controlled from the UI. |
| − | The default connection varies slightly from device to device. For example on 5800 device, navigate to Menu -> Settings -> Connectivity -> Destinations -> Options -> Default Connection | + | The default connection varies slightly from device to device. For example on 5800 device, navigate to ''Menu -> Settings -> Connectivity -> Destinations -> Options -> Default Connection'' to control this setting. Notably, it the setting is set as 'Always Ask', user will be prompted every time. |
| − | to control this setting. | + | |
| − | If you need more control over which configuration is used, what you can do is list the configurations (QNetworkConfigurationManager::allConfigurations()), choose the one you wish to use, and | + | If you need more control over which configuration is used, what you can do is list the configurations ({{Icode|QNetworkConfigurationManager::allConfigurations()}}), choose the one you wish to use, and |
| − | create a QNetworkSession based on that configuration (similarly as in the example snippet above). | + | create a [http://doc.qt.nokia.com/4.7/qnetworksession.html QNetworkSession] based on that configuration (similarly as in the example snippet above). |
=extension= | =extension= | ||
| − | * In one of my previous [ | + | * In one of my previous [[How to do HTTP Get and Post using Qt|article]] I explained the HTTP '''GET''' and '''POST''' mechanism using Qt's APIs, that article can be easily extended to ask the user at first to select an access point and make that as default connection. |
* The screenshots shown below illustrates the above point clearly: | * The screenshots shown below illustrates the above point clearly: | ||
| Line 94: | Line 116: | ||
=References= | =References= | ||
| − | * [[Setting up environment for Qt Mobility API]] | + | * [[Archived:Setting up environment for Qt Mobility API]] |
* [[Working with Carbide.c++ IDE for Qt Mobility APIs]] | * [[Working with Carbide.c++ IDE for Qt Mobility APIs]] | ||
| − | * [ | + | * [[How to do HTTP Get and Post using Qt]][[Category:MeeGo Harmattan]] [[Category:Symbian]] |
Latest revision as of 04:23, 11 October 2012
Article Metadata
| ID | Creation date | 29th Mar 2010 | |
| Platform | S60 5th Edition | Tested on devices | Nokia N97 |
| Category | Qt | Subcategory | Qt Mobility API |
| Keywords (APIs, classes, methods, functions): QNetworkSession, QNetworkConfigurationManager,QConfigurationManager |
Contents |
Overview
This article demonstrate how to set default access point using the Bearer Management APIs of the Qt's Mobility Package.
Project Configuration File (.pro file)
Add the Qt Mobility project configuration option in the .Pro file as shown below
CONFIG += mobility
MOBILITY += bearer
Header File
Also do add the Qt mobility name space before using any Qt mobility APIs,
QTM_USE_NAMESPACE
Declare a QNetworkSession object in the header file which will help in opening the network connections.
#include <qmobilityglobal.h>
#include <qnetworksession.h>
QNetworkSession* session;
Source File
After declaring the QNetworkSession object we need to use the QNetworkConfigurationManager and QNetworkConfiguration class to ask the user about the access point and make that as a default connection.
A sample function is shown below :
QNetworkConfigurationManager manager;
const bool selectIap = (manager.capabilities()& QNetworkConfigurationManager::CanStartAndStopInterfaces);
QNetworkConfiguration defaultIap = manager.defaultConfiguration();
if(!defaultIap.isValid() && (!selectIap && defaultIap.state() != QNetworkConfiguration::Active))
{
// let the user know that there is no access point available
}
session = new QNetworkSession(defaultIap,this);
session->open();
It is worth noting that QNetworkConfigurationManager::defaultConfiguration() reflects the device's default connection setting, which can be controlled from the UI. The default connection varies slightly from device to device. For example on 5800 device, navigate to Menu -> Settings -> Connectivity -> Destinations -> Options -> Default Connection to control this setting. Notably, it the setting is set as 'Always Ask', user will be prompted every time.
If you need more control over which configuration is used, what you can do is list the configurations (QNetworkConfigurationManager::allConfigurations()), choose the one you wish to use, and create a QNetworkSession based on that configuration (similarly as in the example snippet above).
extension
- In one of my previous article I explained the HTTP GET and POST mechanism using Qt's APIs, that article can be easily extended to ask the user at first to select an access point and make that as default connection.
- The screenshots shown below illustrates the above point clearly:



