简体   繁体   中英

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 += networkservices
    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"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM