×
Namespaces

Variants
Actions
(Difference between revisions)

How to set default access point using Qt Mobility APIs

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Add ArticleMetaData)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
 
Line 62: Line 62:
  
 
Also do add the Qt mobility name space before using any Qt mobility APIs,
 
Also do add the Qt mobility name space before using any Qt mobility APIs,
<code cpp>
+
<code cpp-qt>
 
   QTM_USE_NAMESPACE
 
   QTM_USE_NAMESPACE
 
</code>
 
</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.
 
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>
+
<code cpp-qt>
  
 
#include <qmobilityglobal.h>
 
#include <qmobilityglobal.h>
Line 82: Line 82:
 
A sample function is shown below :
 
A sample function is shown below :
  
<code cpp>
+
<code cpp-qt>
  
 
     QNetworkConfigurationManager manager;
 
     QNetworkConfigurationManager manager;

Latest revision as of 04:23, 11 October 2012

Article Metadata
Compatibility
Platform(s):
Symbian
Article
Created: gaba88 (29 Mar 2010)
Last edited: hamishwillee (11 Oct 2012)
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


Tip.pngTip: Read this article before moving forward: Archived:Setting up environment for Qt Mobility API


Contents

[edit] Overview

This article demonstrate how to set default access point using the Bearer Management APIs of the Qt's Mobility Package.

[edit] Project Configuration File (.pro file)

Add the Qt Mobility project configuration option in the .Pro file as shown below

CONFIG += mobility
MOBILITY += bearer


[edit] 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;

[edit] 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).

[edit] 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:

QDefaultAccessPoint1.jpg QDefaultAccessPoint2.jpg


[edit] References

This page was last modified on 11 October 2012, at 04:23.
70 page views in the last 30 days.
×