Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Revision as of 06:49, 26 July 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

From Wiki
Jump to: navigation, search
Article Metadata

文章
liuting 在 07 Mar 2012 创建
最后由 hamishwillee 在 26 Jul 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

This page was last modified on 26 July 2012, at 06:49.
61 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.

×