开发者

Network session error with QNetworkAccessManager in Qt on a Symbian device

I'm trying to do an httpget on a Symbian mobile device in Qt 4.7.

I tested the program on Windows and on the Symbian emulator and they both work, but when I try it on the Symbian device I get an error:

Network session error.

When I try to do the httpget through the browser in the Symbian device it works, and I see the page.

Here is the network code:

    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)));

Here is the 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 {
        ....

Output of all this:

[Qt Message] reply finished
[Qt Message] server niet bereikbaar:  "Network session error."
  • Nothing wrong with the connection: browser test succeeds
  • Nothing wrong with the code: since it works on emulator

What did I do wrong?

Edit

I also added networkservices to the .pro file:

symbian {
    TARGET.UID3 = 0xeeb46dc7
    TARGET.CAPABILITY += networkserv开发者_StackOverflow中文版ices
    TARGET.EPOCSTACKSIZE = 0x14000
    TARGET.EPOCHEAPSIZE = 0x020000 0x800000
}


I solved it using this:

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;
}

And I added this line in the symbian:{} section in the .pro file:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜