Retrieve weather forecast
-
I decided to use QXmlStreamReader to read a simple xml code retrieve from "http://rss.weatherzone.com.au/?u=12994-1285<=aploc&lc=9388&obs=1&fc=1&warn=1"
but when i'm trying to debug the program exited with code 0xc0000139
I've been digging around on Google and still can't find the answer to my problem
Whenever I used anything involving Qtnetworkd4.dll it raise that problem. Not sure if my code in .pro is wrong or not though.
Here's the code sniplet of part of my project:
@QT += core gui network xml
TARGET = Clock
TEMPLATE = appSOURCES += main.cpp
mainwindow.cppHEADERS += mainwindow.h
FORMS += mainwindow.ui@
a push button in mainwindow:
@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<=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)));
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
}
}
}
}
}@ -
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?
-
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<=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
}
}
}
}}
@ -
It raised the same error, the 0xc0000139 thing. Keep getting that every time i use QtNetwork
-
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 -1073741511I just know that -1073741511 = 0xc0000139.
-
I don't see possible error here. It is somewhere else... Set some breakpoints and debug your app step-by-step
-
Well I managed to clean up the Build Environment and it works now, turn out I was using the wrong environment variables.
-
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') -
Ok I know what to do now, thanks a lot AcerExtensa
-
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<=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--?
-
lol silly me, I didn't put
@reader.readNext();@
in the while loop, and I keep checking my slot connections
-
-Hm, it can be only because of while loop. but it should not take more then some seconds...-
-
"
TuesdayMostly sunny
14°C - 25°C
WednesdayMostly sunny
14°C - 26°C
ThursdayMostly sunny
13°C - 28°C
FridayMostly 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?
-
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>° -
This post is deleted!