Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. QtonPi
  4. Weather Info
Forum Updated to NodeBB v4.3 + New Features

Weather Info

Scheduled Pinned Locked Moved Unsolved QtonPi
8 Posts 3 Posters 2.1k Views 2 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.
  • E Offline
    E Offline
    emrullahozdemir
    wrote on last edited by
    #1

    Hi, im using qt creator and i am designing gui for home automation and i want to add to main window ( core gui ) weather info ( should be always updated and should get location info from gps ) I searched the internet and i found qml things but my gui is not qml. How i can do this?

    1 Reply Last reply
    0
    • CKurduC Offline
      CKurduC Offline
      CKurdu
      wrote on last edited by
      #2

      Hi Emrullah,
      You can use qgeopositioninfo and qgeopositioninfosource classes and you can use QWidget based controls and Qt network facilities to get weather info from any weather service ( yahoo, openweathermap, etc).

      You reap what you sow it

      1 Reply Last reply
      0
      • E Offline
        E Offline
        emrullahozdemir
        wrote on last edited by
        #3

        Thanks for the replying! Actually i want to add this xhtml code (http://www.mgm.gov.tr/sunum/tahmin-klasik-5070.aspx?m=ANKARA&basla=1&bitir=5&rC=111&rZ=fff) to my mainwindow. How can i do this?

        Pablo J. RoginaP 1 Reply Last reply
        0
        • CKurduC Offline
          CKurduC Offline
          CKurdu
          wrote on last edited by
          #4

          Your weather service is returning png. Below code shows the image. For your first question, you need a reverse geolocation service to define the location of the city in Turkey. Like https://locationiq.com/#demo.

          MainWindow::MainWindow(QWidget *parent) :
              QMainWindow(parent),
              ui(new Ui::MainWindow)
          {
              ui->setupUi(this);
              man = new QNetworkAccessManager();
              connect(man,&QNetworkAccessManager::finished,this,&MainWindow::rfinished);
          
              req = new QNetworkRequest(QUrl("https://www.mgm.gov.tr/sunum/tahmin-klasik-5070.aspx?m=ANKARA&basla=1&bitir=5&rC=111&rZ=fff"));
              rep = man->get(*req);
          }
          
          MainWindow::~MainWindow()
          {
              delete ui;
          }
          
          void MainWindow::rfinished(QNetworkReply *prep)
          {
             if(prep->error() != QNetworkReply::NoError)
             {
                 prep->deleteLater();
                 return;
             }
             QFile image("weather.png");
             if(!image.open(QIODevice::WriteOnly))
             {
                 prep->deleteLater();
                 return;
             }
             QByteArray result = prep->readAll();
             image.write(result);
             image.close();
             QImage img("weather.png");
             ui->label->setPixmap(QPixmap::fromImage(img));
          
             prep->deleteLater();
          }
          
          

          You reap what you sow it

          E 1 Reply Last reply
          0
          • E emrullahozdemir

            Thanks for the replying! Actually i want to add this xhtml code (http://www.mgm.gov.tr/sunum/tahmin-klasik-5070.aspx?m=ANKARA&basla=1&bitir=5&rC=111&rZ=fff) to my mainwindow. How can i do this?

            Pablo J. RoginaP Offline
            Pablo J. RoginaP Offline
            Pablo J. Rogina
            wrote on last edited by
            #5

            @emrullahozdemir from CKurdu example, you need to make the hard-code city value (i.e. ANKARA) variable, if not weather will always display for such location...

            req = new QNetworkRequest(QUrl("https://www.mgm.gov.tr/sunum/tahmin-klasik-5070.aspx?m=ANKARA&basla=1&bitir=5&rC=111&rZ=fff"));
            

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • CKurduC CKurdu

              Your weather service is returning png. Below code shows the image. For your first question, you need a reverse geolocation service to define the location of the city in Turkey. Like https://locationiq.com/#demo.

              MainWindow::MainWindow(QWidget *parent) :
                  QMainWindow(parent),
                  ui(new Ui::MainWindow)
              {
                  ui->setupUi(this);
                  man = new QNetworkAccessManager();
                  connect(man,&QNetworkAccessManager::finished,this,&MainWindow::rfinished);
              
                  req = new QNetworkRequest(QUrl("https://www.mgm.gov.tr/sunum/tahmin-klasik-5070.aspx?m=ANKARA&basla=1&bitir=5&rC=111&rZ=fff"));
                  rep = man->get(*req);
              }
              
              MainWindow::~MainWindow()
              {
                  delete ui;
              }
              
              void MainWindow::rfinished(QNetworkReply *prep)
              {
                 if(prep->error() != QNetworkReply::NoError)
                 {
                     prep->deleteLater();
                     return;
                 }
                 QFile image("weather.png");
                 if(!image.open(QIODevice::WriteOnly))
                 {
                     prep->deleteLater();
                     return;
                 }
                 QByteArray result = prep->readAll();
                 image.write(result);
                 image.close();
                 QImage img("weather.png");
                 ui->label->setPixmap(QPixmap::fromImage(img));
              
                 prep->deleteLater();
              }
              
              
              E Offline
              E Offline
              emrullahozdemir
              wrote on last edited by
              #6

              @CKurdu it says "man", "req" and "rep" was not declared in this scope

              Pablo J. RoginaP 1 Reply Last reply
              0
              • E emrullahozdemir

                @CKurdu it says "man", "req" and "rep" was not declared in this scope

                Pablo J. RoginaP Offline
                Pablo J. RoginaP Offline
                Pablo J. Rogina
                wrote on last edited by
                #7

                @emrullahozdemir said in Weather Info:

                it says "man", "req" and "rep" was not declared in this scope

                That's pure C++ issue. Are you able to get them in scope? Think about members of MainWindow class for instance...

                Upvote the answer(s) that helped you solve the issue
                Use "Topic Tools" button to mark your post as Solved
                Add screenshots via postimage.org
                Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • E Offline
                  E Offline
                  emrullahozdemir
                  wrote on last edited by
                  #8

                  can i show the info in webview? load(url) doesnt work.

                  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