×
Namespaces

Variants
Actions
(Difference between revisions)

在QT中如何通过网络接入点ID来获得相应的网关信息

From Nokia Developer Wiki
Jump to: navigation, search
liuting (Talk | contribs)
(Liuting - - 相关链接)
liuting (Talk | contribs)
(Liuting -)
Line 1: Line 1:
[[Category:Draft]]
+
[[Category:Qt]][[Category:Qt Mobility]]
''Delete instructional text in italic''
+
 
+
{{Abstract|This article explains how to ... }} ''Replace the abstract text with a short paragraph (or sentence) describing what the topic covers.''
+
 
+
''Enter article metadata as described below. Note that this template can be placed anywhere in the article. Do not remove parameters that you do not use''
+
{{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= <!-- Format YYYYMMDD -->
+
|author= <!-- Display as link [[User:username]] -->
+
}}
+
 
+
 
== 介绍==
 
== 介绍==
 
在开发过程中,我们有时候需要获得接入点得网关信息,遗憾的是QT 没有提供这样的 函数,所以我们必须在通过SYMBIAN API 传入相应的接入点ID,来获得网关信息,实现代码如下:
 
在开发过程中,我们有时候需要获得接入点得网关信息,遗憾的是QT 没有提供这样的 函数,所以我们必须在通过SYMBIAN API 传入相应的接入点ID,来获得网关信息,实现代码如下:

Revision as of 05:32, 8 March 2012

介绍

在开发过程中,我们有时候需要获得接入点得网关信息,遗憾的是QT 没有提供这样的 函数,所以我们必须在通过SYMBIAN API 传入相应的接入点ID,来获得网关信息,实现代码如下:

具体实现

首先需要设置.PRO文件

LIBS += -lcmmanager

其次引入头文件

#include <cmmanager.h>
#include <cmconnectionmethoddef.h>

实现proxyL函数

void  proxyL( int aIapId)
{
TBool usesProxy( EFalse );
RCmManager cm;
cm.OpenLC();
usesProxy = cm.GetConnectionMethodInfoBoolL( aIapId, CMManager::ECmProxyUsageEnabled );
TUint32 proxyServerPort = 0;
HBufC* proxyServerName = NULL;
if(usesProxy)
{
proxyServerPort = cm.GetConnectionMethodInfoIntL( aIapId, CMManager::ECmProxyPortNumber );
proxyServerName = cm.GetConnectionMethodInfoStringL( aIapId, CMManager::ECmProxyServerName );
}
if(!proxyServerName)
{
noproxy();
}
else
{
CleanupStack::PushL(proxyServerName);
QString proxyHostName("");
int len = proxyServerName->Length();
if(len > 0)
{
proxyHostName = QString((QChar*)proxyServerName->Ptr(), len);
}
if (proxyHostName.isEmpty())
{
noproxy();
}
else
{
m_isProxyUsed = true;
m_proxy.setType(QNetworkProxy::HttpProxy);
m_proxy.setHostName(proxyHostName);
m_proxy.setPort(proxyServerPort);
}
CleanupStack::PopAndDestroy( proxyServerName );
}
CleanupStack::PopAndDestroy(); // cm
qDebug() << "<< DownloadMgtServer::proxyL()";
 
}

实现noproxy函数

void noproxy(){
m_isProxyUsed = false;
m_proxy.setType(QNetworkProxy::NoProxy);
m_proxy.setHostName("");
m_proxy.setPort(0);
 
}

最后在我们的应用中通过QNetWorkConfigutation得到接入点ID传入proxy 函数,并设置应用程序网关

QNetworkConfiguration config = session->configuration();
QString iapID = config.identifier()
 
if (iapId != "") {
if (iapId.startsWith("i_", Qt::CaseInsensitive)) {
 
iapId.remove(0, 2);
}
 
int identifier = iapId.toInt();
proxyL(identifier);
 
QNetworkProxy::setApplicationProxy(m_proxy);

相关链接


Add categories below. Remove Category:Draft when the page is complete or near complete

97 page views in the last 30 days.
×