2011-03-14 43 views
0

我想在Qt 4.7的Symbian移動設備上做一個httpget。在Symbian設備Qt QNetworkAccessManager網絡會話錯誤

我測試了在Windows和Symbian模擬器,他們都工作程序,但是當我嘗試它的Symbian設備上我得到一個錯誤:

Network session error.

當我嘗試做HTTPGET通過瀏覽器在Symbian設備上工作,我看到了頁面。

下面是網絡代碼:

QNetworkAccessManager *manager = new QNetworkAccessManager(this); 
    connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); 
    manager->get(QNetworkRequest(QUrl(Consts::webserviceURL + Consts::servletLogin + "?" 
             + Consts::username + "=" + username + "&" 
             + Consts::password + "=" + password))); 

這裏是replyFinished:

void LoginDialog::replyFinished(QNetworkReply* reply){ 
    qDebug() << "reply finished"; 

    if (reply->error()) { 
      ui->lbl_loginerror->setText("server niet bereikbaar: " + reply->errorString()); 
      qDebug() << "server niet bereikbaar: " << reply->errorString(); 

    } 
    else { 
     .... 

這一切輸出:

[Qt Message] reply finished 
[Qt Message] server niet bereikbaar: "Network session error." 
  • 沒有錯的連接:瀏覽器測試成功
  • 代碼沒有錯:因爲它在仿真器上工作

我做錯了什麼?

編輯

我還添加了網絡服務的.pro文件:

symbian { 
    TARGET.UID3 = 0xeeb46dc7 
    TARGET.CAPABILITY += networkservices 
    TARGET.EPOCSTACKSIZE = 0x14000 
    TARGET.EPOCHEAPSIZE = 0x020000 0x800000 
} 

回答

0

我解決了它使用此:

QString DataConnector::get(QString path){ 
    QNetworkAccessManager NAManager; 
    QUrl url (path); 
    QNetworkRequest request(url); 
    QNetworkReply *reply = NAManager.get(request); 
    QEventLoop eventLoop; 
    QObject::connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit())); 
    eventLoop.exec(); 
    QString replyString = reply->readAll(); 
    return replyString; 
} 

而且我在加入這一行的symbian:{}.pro文件:

symbian: { 
    TARGET.CAPABILITY = "NetworkServices ReadUserData WriteUserData" 
}