Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. [Solved]QXmlStreamReader Problem

[Solved]QXmlStreamReader Problem

Scheduled Pinned Locked Moved Installation and Deployment
15 Posts 2 Posters 6.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MaddinM
    wrote on last edited by
    #4

    This is the xml File.

    @<?xml version="1.0" encoding="UTF-8"?>
    <weather>
    <curren_weather>
    <humidity>80</humidity>
    <temp_unit>c</temp_unit>
    <wind>
    <speed>5</speed>
    <dir>NNE</dir>
    <wind_unit>kph</wind_unit>
    </wind>
    <temp>2</temp>

    <pressure>1025</pressure>
    <weather_text>Cloudy</weather_text>
    <weather_code>3</weather_code>
    </curren_weather>
    <forecast>
    <date>2013-02-25</date>
    <temp_unit>c</temp_unit>
    <day_max_temp>5</day_max_temp>
    <night_min_temp>2</night_min_temp>
    <day>
    <weather_text>Overcast skies</weather_text>
    <weather_code>3</weather_code>
    <wind>
    <speed>22</speed>
    <dir>NNE</dir>
    <dir_degree>21</dir_degree>
    <wind_unit>kph</wind_unit>
    </wind>
    </day>
    <night>
    <weather_text>Overcast skies</weather_text>
    <weather_code>3</weather_code>
    <wind>
    <speed>22</speed>
    <dir>NNE</dir>
    <dir_degree>11</dir_degree>
    <wind_unit>kph</wind_unit>
    </wind>
    </night>
    </forecast>
    <forecast>
    <date>2013-02-26</date>
    <temp_unit>c</temp_unit>
    <day_max_temp>5</day_max_temp>
    <night_min_temp>1</night_min_temp>
    <day>
    <weather_text>Light drizzle</weather_text>
    <weather_code>51</weather_code>
    <wind>
    <speed>22</speed>
    <dir>ENE</dir>
    <dir_degree>58</dir_degree>
    <wind_unit>kph</wind_unit>
    </wind>
    </day>
    <night>
    <weather_text>Mist</weather_text>
    <weather_code>10</weather_code>
    <wind>
    <speed>14</speed>
    <dir>NNE</dir>
    <dir_degree>29</dir_degree>
    <wind_unit>kph</wind_unit>
    </wind>
    </night>
    </forecast>
    </weather>@

    Maybe it helps.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #5

      Depends on what you mean by wrong.

      Your application working directory is in the build directory so it won't find forecast.xml.

      You need to use the complete path to forecast.xml ie @QFile file("/home/myusername/mycodepath/forecast.xml")@

      Or have it in the same folder than application.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MaddinM
        wrote on last edited by
        #6

        The forecast.xml file is in the folder of the application and in the src folder.
        Their are other folder like assets, translations, x86 and .settings

        its an Blackberry 10 Native application

        In the IDE iam clicking rightclick on the xml file -> Properties and their is a path but copying it wont work.
        I mean copying works but when I past it, the open call is still false

        I copying the file to every folder in my project.

        Maybe their is somethin wrong with the open function call

        Well I see, You're getting out of ideas. Thanks for the help anyway.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #7

          forecast.xml should not be were your code is but were your binary is.
          If you want it somewhere else, give the complete path to QFile.
          If the file is not meant to change, you can also embedded it using qrc.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MaddinM
            wrote on last edited by
            #8

            What do you mean with Binary? where the c++ files are?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #9

              No, the c++ file are the sources, the binary is the executable file that gets generated from the sources.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • M Offline
                M Offline
                MaddinM
                wrote on last edited by
                #10

                Ah, Ok. Almost forgot. Well thier is a folder called Binary. Tried to copy the forecast.xml thier but with no succes for the open call. It is still false. I got the feeling that Windows is getting in the way with the right path. Iam set up a linux and try my luck their.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #11

                  Are you sure that the file is put with the binary ? Do you run the binary on windows or on your target ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    MaddinM
                    wrote on last edited by
                    #12

                    I run the binary on windows. I use a simulator.

                    This is my project tree and in the folder x86 are the binaries i think.

                    !http://img201.imageshack.us/img201/7232/projecttree.jpg(Project Tree)!

                    I copied the file to C:/forecast.xml and tried

                    QFile file("C:/forecast.xml");

                    with no success

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      MaddinM
                      wrote on last edited by
                      #13

                      I dont know anymore. I reply the current sorce code. Its messy hope you dont mind.

                      @// Default empty project template

                      #include "Test.hpp"

                      #include <bb/cascades/Application>
                      #include <bb/cascades/QmlDocument>
                      #include <bb/cascades/AbstractPane>

                      #include <bb/cascades/GroupDataModel>
                      #include <bb/cascades/ListView>

                      #include <stdio.h>

                      #include <bb/cascades/Color>

                      #include <bb/data/XmlDataAccess.hpp>

                      using namespace bb::cascades;

                      Test::Test(bb::cascades::Application *app) :
                      QObject(app) {

                      bool testOpen = true;

                      QString name;
                      QFile file(QString("/test/src/forecast.xml"));

                      //file.open(QIODevice::ReadOnly);

                      /if() {
                      testOpen = true;
                      } else {
                      testOpen = false;
                      }
                      /

                      //file.open(QIODevice::ReadOnly);

                      QXmlStreamReader xml(&file);
                      //while (!xml.atEnd())
                      //{
                      xml.readNext();
                      name = xml.name().toString();
                      //}
                      if (xml.hasError())
                      {
                      name = xml.errorString();
                      }
                      //file.close();

                      //QFile file("forecast.xml");
                      /*QFile file("forecast.xml");

                      QXmlStreamReader xml(&file);

                      //while(!xml.atEnd()) {
                      xml.readNext();
                      //if(xml.readNextStartElement()) {
                      name = xml.name().toString();
                      //}
                      qDebug() << xml.lineNumber() << xml.name().toString();

                      //}

                      if (xml.hasError()) {
                      name = xml.errorString();

                      }*/

                      // create scene document from main.qml asset
                      // set parent to created document to ensure it exists for the whole application lifetime
                      QmlDocument qml = QmlDocument::create("asset:///main.qml").parent(this);
                      QDeclarativePropertyMap
                      propertyMap = new QDeclarativePropertyMap;

                      //insert string mystring and 519-555-0199 into name and phone
                      propertyMap->insert("name", QVariant(file.open(QIODevice::ReadOnly | QIODevice::Text)));
                      propertyMap->insert("phone", QVariant(QString("519-555-0199")));

                      qml->setContextProperty("propertyMap", propertyMap);

                      // create root object for the UI
                      AbstractPane *root = qml->createRootObject<AbstractPane>();
                      // set created root object as a scene
                      app->setScene(root);
                      }

                      @

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #14

                        If your software runs on the emulator, put forecast.xml in the same directory as the executable on the emulator

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          MaddinM
                          wrote on last edited by
                          #15

                          Hi,

                          It was the wrong path after all.

                          I did

                          QFile file("app/native/assets/forecast.xml");

                          and now its working.

                          Thx for the help.

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved