Weather Info
-
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?
-
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). -
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?
-
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(); }
-
@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"));
-
@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...
-
can i show the info in webview? load(url) doesnt work.