Symbian 设备上 Qt 中 QNetworkAccessManager 出现网络会话错误

发布于 2024-10-21 13:18:16 字数 1553 浏览 9 评论 0原文

我正在尝试在 Qt 4.7 中的 Symbian 移动设备上执行 httpget。

我在 Windows 和 Symbian 模拟器上测试了该程序,它们都可以工作,但是当我在 Symbian 设备上尝试它时,出现错误:

网络会话错误。

当我尝试通过 Symbian 设备中的浏览器执行 httpget 时,它起作用了,并且我看到了该页面。

这是网络代码:

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

这是回复完成:

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
}

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
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪化雨蝶 2024-10-28 13:18:16

我使用以下方法解决了这个问题:

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

我在 .pro 文件的 symbian:{} 部分添加了这一行:

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

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"
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文