December 6, 2010

Markus Liebe Markus Liebe
Lab Rat
40 posts

[solved] QML app asks for internet connection on maemo device

Page  
1

Hi there,

I wrote a small qml app which uses a XmlListModel filled via an xml in a qrc file. The app runs fine in the QtSimulator. When I deploy the app onto my maemo device (n900) and start it there, the device wants to open a internet connection. The whole app has no reference to the internet. The xml does not even reference a schema… any hints why that happens?

As soon as I connect the device to the internet the applications runs fine.

It seems to that somehow the QNetworkAccessManager makes the device think it needs an internet connection.

I would appreciate any help!

Regards,
Markus

17 replies

December 6, 2010

fcrochik fcrochik
Lab Rat
517 posts

It seems like a bug to me… I would try to reduce to smallest subset of code possible and if the error persists file as a bug

 Signature 

Certified Specialist & Qt Ambassador Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop… Qt everywhere!

December 6, 2010

anselmolsm anselmolsm
Ant Farmer
417 posts

hm… looks like a bug to me too. Fill a bug report [bugreports.qt.nokia.com] and post its number here, so we (and other guys in the future) can follow :-)

 Signature 

Anselmo L. S. Melo (anselmolsm)
www.anselmolsm.org

December 7, 2010

xsacha xsacha
Lab Rat
517 posts

Wait, you’re specifically using QNetworkAccessManager or you just mean that XmlListModel uses this?
You have NETWORKACCESS / capability in your PRO file?
And does it work in Simulator if you have turned off your internet? It may be requesting internet but finds it is already enabled in Simulator.

 Signature 

- Sacha

December 7, 2010

Markus Liebe Markus Liebe
Lab Rat
40 posts

It’s just the default QNetworkAccessManager that is used by the QDeclarativeEngine to do the transparent NetworkAccess. I do not use a special QNetworkAccessManager.
In the .pro file Qt is configured like that:

  1. QT += core gui declarative

Concerning the Simulator: What I already tried was switching off the internet connection on OS X. But even without the computer beeing connected to the internet the app worked well in the simulator.

Do you mean turning off the internet in the simulator? I haven’t tried this..thanks for the hint. I will check it tonight.

December 7, 2010

Markus Liebe Markus Liebe
Lab Rat
40 posts

The cpp part of the app is really just a QMainWindow containing a QDeclarativeView as centralWidget. The rest is implemented in qml.
So I tried to use the qmlviewer to display the qml files. To do that I did not use a qrc file containing the xml, but instead put the xml file into the qml directory. Which lead to:

  1.  XmlListModel {
  2.         id: model
  3.         source: "foo.xml"
  4. [...]
  5. }

instead of
  1.  XmlListModel {
  2.         id: model
  3.         source: ":/foo.xml"
  4. [...]
  5. }

Using this setup the application works in the qmlViewer and without the n900 asking for an internet connection. =)

I will investigate more tonight.

December 7, 2010

Markus Liebe Markus Liebe
Lab Rat
40 posts

Hi.

Ok, i prepared a simple example using a ListView with a simple ListModel and another ListView with a XmlListModel.

The behaviour is like that: In both cases the n900 asks for an internet connection. But only when using the simple ListModel, actual data is displayed.
Using the XmlListModel results in
1) the connection window popping up
2) me, canceling the connection dialog
3) the application does not display anything

Using the simple ListModel:
1) the connection window popping up
2) me, canceling the connection dialog
3) the application displays the data

For the interested developer I pasted the sample code.
( I will most likely create a bug report soon, and put the link into this discussion then)

Regards,
Markus

devo.pro:

  1. QT       += core gui declarative
  2.  
  3. CONFIG += mobility
  4. MOBILITY =
  5.  
  6. TARGET = networkTest
  7. TEMPLATE = app
  8.  
  9.  
  10. SOURCES += main.cpp\
  11.         mainwindow.cpp
  12.  
  13. HEADERS  += mainwindow.h
  14.  
  15. FORMS    += mainwindow.ui
  16.  
  17. OTHER_FILES += \
  18.     main.qml \
  19.     test.xml
  20.  
  21. RESOURCES += \
  22.     res.qrc
  23.  
  24. maemo5 {
  25.     isEmpty(PREFIX):PREFIX = /usr/local
  26.     BINDIR = $$PREFIX/bin
  27.     DATADIR = $$PREFIX/share
  28.  
  29.     DEFINES += DATADIR=\\\"$$DATADIR\\\" \
  30.        PKGDATADIR=\\\"$$PKGDATADIR\\\"
  31.  
  32.    target.path = $$BINDIR
  33.  
  34.    INSTALLS += target
  35. }

main.cpp:

  1. #include <QtGui/QApplication>
  2. #include "mainwindow.h"
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6.     QApplication a(argc, argv);
  7.     MainWindow w;
  8.     w.resize(800,480);
  9.     w.show();
  10.  
  11.     return a.exec();
  12. }

mainwindow.h

  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5. #include <QDeclarativeView>
  6.  
  7. namespace Ui {
  8.     class MainWindow;
  9. }
  10.  
  11. class MainWindow : public QMainWindow
  12. {
  13.     Q_OBJECT
  14.  
  15. public:
  16.     explicit MainWindow(QWidget *parent = 0);
  17.     ~MainWindow();
  18.  
  19. protected:
  20.     void changeEvent(QEvent *e);
  21.  
  22. private:
  23.     Ui::MainWindow *ui;
  24.  
  25.     QDeclarativeView *m_view;
  26. };
  27.  
  28. #endif // MAINWINDOW_H

mainwindow.cpp:

  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QDeclarativeEngine>
  4. #include <QDebug>
  5.  
  6. MainWindow::MainWindow(QWidget *parent) :
  7.     QMainWindow(parent),
  8.     ui(new Ui::MainWindow)
  9. {
  10.     ui->setupUi(this);
  11.     m_view = new QDeclarativeView;
  12.     m_view->setSource(QUrl("qrc:main.qml"));
  13.     m_view->engine()->addImportPath("qrc:/");
  14.     qDebug() << m_view->engine()->importPathList();
  15.     setCentralWidget(m_view);
  16.     setWindowTitle(tr("Losungen"));
  17. }
  18.  
  19. MainWindow::~MainWindow()
  20. {
  21.     delete ui;
  22. }
  23.  
  24. void MainWindow::changeEvent(QEvent *e)
  25. {
  26.     QMainWindow::changeEvent(e);
  27.     switch (e->type()) {
  28.     case QEvent::LanguageChange:
  29.         ui->retranslateUi(this);
  30.         break;
  31.     default:
  32.         break;
  33.     }
  34. }

test.xml:

  1. <root>
  2. <item>
  3.  <name>Apple</name>
  4.  <cost>2.45</cost>
  5. </item>
  6. <item>
  7.  <name>Orange</name>
  8.  <cost>3.25</cost>
  9. </item>
  10. <item>
  11.  <name>Banana</name>
  12.  <cost>1.95</cost>
  13. </item>
  14. </root>

main.qml:

  1. import Qt 4.7
  2.  
  3. Rectangle {
  4.     id: container
  5.     width: 800
  6.     height: 480
  7.  
  8.     XmlListModel {
  9.         id: model
  10.         source: "test.xml"
  11.         query: "//item"
  12.  
  13.         XmlRole { name: "name"; query: "name/string()" }
  14.         XmlRole { name: "cost"; query: "cost/string()" }
  15.     }
  16.  
  17.     ListModel {
  18.         id: fruitModel
  19.  
  20.              ListElement {
  21.                  name: "Apple"
  22.                  cost: 2.45
  23.              }
  24.              ListElement {
  25.                  name: "Orange"
  26.                  cost: 3.25
  27.              }
  28.              ListElement {
  29.                  name: "Banana"
  30.                  cost: 1.95
  31.              }
  32.     }
  33.  
  34. // mainView: asks for connection as well,
  35. // but displays data without connection, too
  36.  
  37. //    ListView {
  38. //        id: mainView
  39. //        anchors.fill: parent
  40. //        delegate: Text {text: name}
  41. //        model: fruitModel
  42. //        spacing: 5
  43. //        anchors.margins: 5
  44. //    }
  45.  
  46.     // mainView2 asks for internet connection and does not display any data
  47.     // if there is no connection made
  48.     ListView {
  49.         id: mainView2
  50.         anchors.fill: parent
  51.         delegate: Text {text: name}
  52.         model: model
  53.         spacing: 5
  54.         anchors.margins: 5
  55.     }
  56.  
  57. }

December 7, 2010

fcrochik fcrochik
Lab Rat
517 posts

It looks more and more like a bug that will probable take the developer 5 minutes to find and fix but unfortunately will take a VERY long time to make into an official release… You may need to think about a workaround. Any reason not to copy the files to a folder and access them from there?

 Signature 

Certified Specialist & Qt Ambassador Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop… Qt everywhere!

December 7, 2010

Markus Liebe Markus Liebe
Lab Rat
40 posts

I created a bug report.
I think I put it into the wrong category though: Qt Quick Components.
… was the only one with a reference to Qt Quick..

Anyway: here is the Bugreport [bugreports.qt.nokia.com]

December 7, 2010

anselmolsm anselmolsm
Ant Farmer
417 posts

Qt Quick Components is the official name of Qt-Components. The correct category for your bug is Qt, component Declarative (QML) [bugreports.qt.nokia.com]

 Signature 

Anselmo L. S. Melo (anselmolsm)
www.anselmolsm.org

December 7, 2010

Markus Liebe Markus Liebe
Lab Rat
40 posts

fcrochik wrote:
Any reason not to copy the files to a folder and access them from there?

Well, not really. I just like the convenience of the qrc files. You can edit them in the Creator. Then let QtCreator create the .deb package for deployment and that’s it. No hassle with manually putting files into the debian folder of the build directory to get the files into place. =)

December 7, 2010

fcrochik fcrochik
Lab Rat
517 posts

I agree… I am just concerned that you won’t have a solution in a short time frame so you probably need a plan B.

The one side effect of having the qml files on a folder is that you can allow people to “enhance” them … of course that also means they can break them :)

What I have done in the past was have the application on startup “extract” the files from the resources to a local folder if they didn’t exist. This way if any problems happen the user can just delete the files from the local folder and the application will recreate them.

 Signature 

Certified Specialist & Qt Ambassador Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop… Qt everywhere!

December 8, 2010

Markus Liebe Markus Liebe
Lab Rat
40 posts

If any of the trolls is watching this thread: How can I move my Bugreport [bugreports.qt.nokia.com] into the correct category (Qt, component Declarative (QML) [bugreports.qt.nokia.com]) ?

December 8, 2010

Volker Volker
Ant Farmer
5428 posts

You cannot move it yourself, the “edit issue” is disabled for us users. The only possibility I see is leaving a comment and/or creating a new issue in the right place.

December 8, 2010

fcrochik fcrochik
Lab Rat
517 posts

The Trolls are pretty good on checking the bug reports and move them as necessary… More important than the group is the assigned resource and once this one sees something that is not his “expertise/responsibility” he will probably reassign.

At least, that has been my experience…

 Signature 

Certified Specialist & Qt Ambassador Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop… Qt everywhere!

December 9, 2010

Markus Liebe Markus Liebe
Lab Rat
40 posts

Seems as if the category was already corrected: Bugreport [bugreports.qt.nokia.com]

Page  
1

  ‹‹ Problems Compiling QML app in Visual Studio      QML Map Element ››

You must log in to post a reply. Not a member yet? Register here!