Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Read data of a website
Forum Updated to NodeBB v4.3 + New Features

Read data of a website

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 7 Posters 1.6k Views 4 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.
  • L Offline
    L Offline
    Linz
    wrote on 12 Jun 2021, 13:30 last edited by Linz 6 Dec 2021, 14:42
    #5

    I fixed the error, something with my proxy was off ^^

    Do you have an idea how I can convert the QByteArray buffer to a char? Would It make way more easy to access the values I need.

    V 1 Reply Last reply 12 Jun 2021, 15:14
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 12 Jun 2021, 15:02 last edited by
      #6

      Hi,

      No need to convert anything.

      You can access the internal data using the QByteArray::data function.

      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
      2
      • L Linz
        12 Jun 2021, 13:30

        I fixed the error, something with my proxy was off ^^

        Do you have an idea how I can convert the QByteArray buffer to a char? Would It make way more easy to access the values I need.

        V Offline
        V Offline
        VRonin
        wrote on 12 Jun 2021, 15:14 last edited by VRonin 6 Dec 2021, 15:14
        #7

        @Linz said in Read data of a website:

        Do you have an idea how I can convert the QByteArray buffer to a char? Would It make way more easy to access the values I need.

        Don't do this.

        @artwaw said in Read data of a website:

        To parse XML you can use https://doc.qt.io/qt-5/qxmlstreamreader.html

        Do this!

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        4
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 12 Jun 2021, 18:26 last edited by
          #8

          I somehow missed the XML part.

          My fellows are correct, use QXmlStreamReader.

          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
          1
          • L Offline
            L Offline
            Linz
            wrote on 14 Jun 2021, 15:42 last edited by
            #9

            Sorry for bothering you: I read the documentation for QXmlStreamReader, but I still have no clue how to filter the data. Maybe I am still missing the basics too much to understand what I need...

            If I refer to the picture I want to save the first value 49.986, the second value 132.3 and the third value 0 in an array(s) of type double (to plot it later on).

            But which function could do this for me?
            I tried something like:
            void QXmlStreamReader::addData(const QByteArray &buffer);

            but it doesn't work. I could filter it easily if it would have been an array of char :/

            J 1 Reply Last reply 14 Jun 2021, 15:56
            0
            • K Offline
              K Offline
              Kent-Dorfman
              wrote on 14 Jun 2021, 15:55 last edited by
              #10

              higher level:

              curl
              wget

              1 Reply Last reply
              1
              • L Linz
                14 Jun 2021, 15:42

                Sorry for bothering you: I read the documentation for QXmlStreamReader, but I still have no clue how to filter the data. Maybe I am still missing the basics too much to understand what I need...

                If I refer to the picture I want to save the first value 49.986, the second value 132.3 and the third value 0 in an array(s) of type double (to plot it later on).

                But which function could do this for me?
                I tried something like:
                void QXmlStreamReader::addData(const QByteArray &buffer);

                but it doesn't work. I could filter it easily if it would have been an array of char :/

                J Offline
                J Offline
                JonB
                wrote on 14 Jun 2021, 15:56 last edited by
                #11

                @Linz
                You just want to parse input XML. I don't think you'll particularly be needing QXmlStreamReader::addData(). You're just wanting to read elements and access values.

                There is a Qt example at https://doc.qt.io/qt-5/qtxml-streambookmarks-example.html. But for you you're only interested in the XbelReader::readXBEL() part. It should get you started on how to read through an XML document.

                1 Reply Last reply
                1
                • V Offline
                  V Offline
                  VRonin
                  wrote on 14 Jun 2021, 16:05 last edited by VRonin
                  #12
                  const QByteArray replyData = reply->readAll();
                  QXmlStreamReader xmlreader(replyData);
                  bool rStarted = false;
                  while (!xmlreader.atEnd() && !xmlreader.hasError()) {
                      switch(xmlreader.readNext()){
                      case QXmlStreamReader::StartElement:
                          if(xmlreader.name()==QLatin1String("r"))
                              rStarted = true;
                          else if(rStarted && xmlreader.name()==QLatin1String("f"))
                              qDebug() << "f" << xmlreader.readElementText();
                          else if(rStarted && xmlreader.name()==QLatin1String("z"))
                              qDebug() << "z" << xmlreader.readElementText();
                          else if(rStarted && xmlreader.name()==QLatin1String("p"))
                              qDebug() << "p" << xmlreader.readElementText();
                          else if(rStarted && xmlreader.name()==QLatin1String("dt"))
                              qDebug() << "dt" << xmlreader.readElementText();
                      break;
                      case QXmlStreamReader::EndElement:
                          if(xmlreader.name()==QLatin1String("r"))
                              rStarted = false;
                      break;
                      default:
                      break;
                      }
                  }
                  

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  L 1 Reply Last reply 14 Jun 2021, 17:23
                  5
                  • V VRonin
                    14 Jun 2021, 16:05
                    const QByteArray replyData = reply->readAll();
                    QXmlStreamReader xmlreader(replyData);
                    bool rStarted = false;
                    while (!xmlreader.atEnd() && !xmlreader.hasError()) {
                        switch(xmlreader.readNext()){
                        case QXmlStreamReader::StartElement:
                            if(xmlreader.name()==QLatin1String("r"))
                                rStarted = true;
                            else if(rStarted && xmlreader.name()==QLatin1String("f"))
                                qDebug() << "f" << xmlreader.readElementText();
                            else if(rStarted && xmlreader.name()==QLatin1String("z"))
                                qDebug() << "z" << xmlreader.readElementText();
                            else if(rStarted && xmlreader.name()==QLatin1String("p"))
                                qDebug() << "p" << xmlreader.readElementText();
                            else if(rStarted && xmlreader.name()==QLatin1String("dt"))
                                qDebug() << "dt" << xmlreader.readElementText();
                        break;
                        case QXmlStreamReader::EndElement:
                            if(xmlreader.name()==QLatin1String("r"))
                                rStarted = false;
                        break;
                        default:
                        break;
                        }
                    }
                    
                    L Offline
                    L Offline
                    Linz
                    wrote on 14 Jun 2021, 17:23 last edited by
                    #13

                    @VRonin Thanks a lot! Where do you define readElementText() since I get the Error:
                    Error: use of undeclared identifier 'readElementText'

                    I tried to define it as QString readElementText() in the header, but it doesn't seem to work.

                    V 1 Reply Last reply 14 Jun 2021, 17:25
                    0
                    • L Linz
                      14 Jun 2021, 17:23

                      @VRonin Thanks a lot! Where do you define readElementText() since I get the Error:
                      Error: use of undeclared identifier 'readElementText'

                      I tried to define it as QString readElementText() in the header, but it doesn't seem to work.

                      V Offline
                      V Offline
                      VRonin
                      wrote on 14 Jun 2021, 17:25 last edited by
                      #14

                      Sorry forgot to add xmlreader. amended now

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      1 Reply Last reply
                      1

                      14/14

                      14 Jun 2021, 17:25

                      • Login

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