×
Namespaces

Variants
Actions
(Difference between revisions)

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

From Nokia Developer Wiki
Jump to: navigation, search
kiran10182 (Talk | contribs)
m (Kiran10182 -)
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Add ArticleMetaData)
 
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= 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= 20120307
 +
|author= [[User:Liuting]]
 +
}}
 
[[Category:Qt]][[Category:Qt Mobility]][[Category:Lang-Chinese]]
 
[[Category:Qt]][[Category:Qt Mobility]][[Category:Lang-Chinese]]
 
== 介绍==
 
== 介绍==
Line 14: Line 36:
 
实现proxyL函数
 
实现proxyL函数
 
<code>
 
<code>
void proxyL( int aIapId)
+
void proxyL( int aIapId)
 
   {
 
   {
 
     TBool usesProxy( EFalse );
 
     TBool usesProxy( EFalse );
Line 85: Line 107:
 
</code>
 
</code>
 
== 相关链接==
 
== 相关链接==
*[[Qt 开发]]
+
*[[Portal:Qt (Chinese)]]
  
  
  
 
''Add categories below. Remove Category:Draft when the page is complete or near complete''
 
''Add categories below. Remove Category:Draft when the page is complete or near complete''

Latest revision as of 09:49, 26 July 2012

Article Metadata

文章
liuting 在 07 Mar 2012 创建
最后由 hamishwillee 在 26 Jul 2012 编辑

[edit] 介绍

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

[edit] 具体实现

首先需要设置.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);

[edit] 相关链接


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

This page was last modified on 26 July 2012, at 09:49.
106 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×