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. Retrieve weather forecast
Forum Updated to NodeBB v4.3 + New Features

Retrieve weather forecast

Scheduled Pinned Locked Moved General and Desktop
19 Posts 4 Posters 6.9k 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.
  • D Offline
    D Offline
    deepnguyen
    wrote on 22 Oct 2012, 05:18 last edited by
    #6

    by the way I'm using QtCreator 2.4.1 base on Qt 4.7.4(32 bit)

    and one more question, when i'm trying to use the QtNetworkAccessManager I can't do
    @#include <QtNetwork>@

    but I have to
    @#include <QtNetwork/QtNetworkAccessManager>@

    the same for QtNetworkReply, QtNetworkRequest

    anyone know the reason to this?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AcerExtensa
      wrote on 22 Oct 2012, 07:34 last edited by
      #7

      You should read reply in slotFinished().

      @
      void MainWindow::on_pushButton_3_clicked()
      {

      QNetworkAccessManager *networkAccessManager = new QNetworkAccessManager(this);
      connect(networkAccessManager, SIGNAL(finished(QNetworkReply*)),this, SLOT(slotFinished(QNetworkReply*)));
      
      QUrl url("http://rss.weatherzone.com.au/?u=12994-1285&lt=aploc&lc=9388&obs=1&fc=1&warn=1");
      
      QNetworkReply *reply = networkAccessManager->get(QNetworkRequest(url));connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(slotError( QNetworkReply::NetworkError)));
      

      }

      void MainWindow::slotFinished(QNetworkReply* reply)
      {
      if(reply->error() != QNetworkReply::NoError)
      {
      qCritical() << reply->errorString();
      return;
      }
      QXmlStreamReader reader( reply );
      reader.readNext();
      while (!reader.atEnd()) {
      if (reader.isStartElement()) {
      if (reader.name() == "title") {
      reader.readNext();
      if (reader.text() == "Brisbane weather forecast") {
      //blah blah blah
      }
      }
      }
      }

      }
      @

      God is Real unless explicitly declared as Integer.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        deepnguyen
        wrote on 22 Oct 2012, 08:00 last edited by
        #8

        It raised the same error, the 0xc0000139 thing. Keep getting that every time i use QtNetwork

        1 Reply Last reply
        0
        • D Offline
          D Offline
          deepnguyen
          wrote on 22 Oct 2012, 08:06 last edited by
          #9

          When I tried to run the file in my debug folder with all the needed dll i got

          Entry Point Not Found

          The procedure entry point _Z15qIsEffectiveTLDRK7QString could not be located in the dynamic link library QtCored4.dll.

          and if I try to debug it it raised

          The program has unexpectedly finished.
          C:\Users\DeepBlue\Documents\Qt\Clock-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug\debug\Clock.exe exited with code -1073741511

          I just know that -1073741511 = 0xc0000139.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AcerExtensa
            wrote on 22 Oct 2012, 08:15 last edited by
            #10

            I don't see possible error here. It is somewhere else... Set some breakpoints and debug your app step-by-step

            God is Real unless explicitly declared as Integer.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              deepnguyen
              wrote on 22 Oct 2012, 08:30 last edited by
              #11

              Well I managed to clean up the Build Environment and it works now, turn out I was using the wrong environment variables.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                deepnguyen
                wrote on 22 Oct 2012, 08:31 last edited by
                #12

                now when I tried to debug i get 2 errors
                Object::connect: No such slot MainWindow::slotFinished(QNetworkReply*) in ..\Clock\mainwindow.cpp:755
                Object::connect: (receiver name: 'MainWindow')
                Object::connect: No such slot MainWindow::slotError( QNetworkReply::NetworkError) in ..\Clock\mainwindow.cpp:757
                Object::connect: (receiver name: 'MainWindow')

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  deepnguyen
                  wrote on 22 Oct 2012, 08:36 last edited by
                  #13

                  Ok I know what to do now, thanks a lot AcerExtensa

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    deepnguyen
                    wrote on 22 Oct 2012, 09:37 last edited by
                    #14

                    My code after I clean up a bit is

                    @void MainWindow::on_pushButton_3_clicked()
                    {

                    QNetworkAccessManager * manager = new QNetworkAccessManager(this);
                    connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slotFinished(QNetworkReply*)));
                    QUrl url("http://rss.weatherzone.com.au/?u=12994-1285&lt=aploc&lc=9388&obs=1&fc=1&warn=1");
                    
                    manager->get(QNetworkRequest(url));
                    

                    }

                    void MainWindow::slotFinished(QNetworkReply* reply)
                    {
                    if(reply->error() != QNetworkReply::NoError)
                    {
                    qCritical() << reply->errorString();
                    return;
                    }
                    QXmlStreamReader reader( reply );
                    reader.readNext();
                    while (!reader.atEnd()) {
                    if (reader.isStartElement()) {
                    if (reader.name() == "title") {
                    reader.readNext();
                    if (reader.text() == "Brisbane weather forecast") {
                    //blah blah blah
                    qDebug()<< reader.text();
                    }
                    }
                    }
                    }

                    }@

                    When I debug, whenever I click the button the program freeze up. Where is the problem--?

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      deepnguyen
                      wrote on 22 Oct 2012, 09:47 last edited by
                      #15

                      lol silly me, I didn't put

                      @reader.readNext();@

                      in the while loop, and I keep checking my slot connections

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        AcerExtensa
                        wrote on 22 Oct 2012, 09:51 last edited by
                        #16

                        -Hm, it can be only because of while loop. but it should not take more then some seconds...-

                        God is Real unless explicitly declared as Integer.

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          deepnguyen
                          wrote on 22 Oct 2012, 11:37 last edited by
                          #17

                          "
                          Tuesday

                          Mostly sunny
                          14°C - 25°C
                          Wednesday

                          Mostly sunny
                          14°C - 26°C
                          Thursday

                          Mostly sunny
                          13°C - 28°C
                          Friday

                          Mostly sunny
                          15°C - 32°C
                          "

                          I'm almost there but I need a way to split this string and my head is going dumb now. How can i get only the Days and the weather status?

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            AcerExtensa
                            wrote on 22 Oct 2012, 11:54 last edited by
                            #18

                            the problem is, your choosen service returns RSS feed with forecast as simple html text in [CDATA]... So, you need to parse it yourself... For example with "QRegExp":http://qt-project.org/doc/qt-4.8/qregexp.html parse days first(there is only 7 days), after that parse temperature, it may always have format like:
                            +/- <min 1 digit - max 2digits>°<ignore symbols> - <ignore symbols> +/- <min 1 digit - max 2 digit>°

                            God is Real unless explicitly declared as Integer.

                            1 Reply Last reply
                            0
                            • J Offline
                              J Offline
                              johndev
                              Banned
                              wrote on 9 Apr 2020, 03:18 last edited by
                              #19
                              This post is deleted!
                              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