kars
30th August 2011, 15:10
Hi
First of all I'm totally new in QT... my boss got a program (sourcecode) based on Qt 4.7.4 and asked me to change parts of that sourcecode. I'm actually a borland c++ programmer.
Well now my question:
I have to implement a http request (send a request, wait for it, and go on with the program). Of course I've browsed through the forum pages and found some sourcecode but I can't get it to work. It's very frustrating.
Here's the piece I found (it's from early 2010):
My questions are:
1) When I just use the connect() function I can't compile. Has something changed the last 1 1/2 years? I'm getting "Invalid conversion from QNetWorkReply* to SOCKET... I' tried QObject::connect function and it compiles correctly.
2) The application is running without a gui and somewhere I read that a Q(Core)Application is needed to work with QEventloop and QTimer... is that correct and how should I implement that?
// Create a QNetworkAccessManageer and start listening for it's finished signal //
QNetworkAccessManager *manager = new QNetworkAccessManager();
// create the URL which we sent over to the gribserver //
QUrl url(myUrl); // myUrl declared somewhere else
// and send the request for the grib //
QNetworkReply *reply = manager->get(QNetworkRequest(url));
QEventLoop loop;
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
QTimer timer;
connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
timer.start(5000);
loop.exec();
QByteArray result = reply->readAll();
if (reply->error()!=QNetworkReply::NoError)
{
qDebug() << "Request failed:" << reply->errorString();
return false;
}
else
{
qDebug() << "Reply from gribserver: " << result;
}
Well, these questions sound pretty stupid but I just can't figure it out how the sourcecode should look like. Any help would be apprechiated.
Cheers
Kars
First of all I'm totally new in QT... my boss got a program (sourcecode) based on Qt 4.7.4 and asked me to change parts of that sourcecode. I'm actually a borland c++ programmer.
Well now my question:
I have to implement a http request (send a request, wait for it, and go on with the program). Of course I've browsed through the forum pages and found some sourcecode but I can't get it to work. It's very frustrating.
Here's the piece I found (it's from early 2010):
My questions are:
1) When I just use the connect() function I can't compile. Has something changed the last 1 1/2 years? I'm getting "Invalid conversion from QNetWorkReply* to SOCKET... I' tried QObject::connect function and it compiles correctly.
2) The application is running without a gui and somewhere I read that a Q(Core)Application is needed to work with QEventloop and QTimer... is that correct and how should I implement that?
// Create a QNetworkAccessManageer and start listening for it's finished signal //
QNetworkAccessManager *manager = new QNetworkAccessManager();
// create the URL which we sent over to the gribserver //
QUrl url(myUrl); // myUrl declared somewhere else
// and send the request for the grib //
QNetworkReply *reply = manager->get(QNetworkRequest(url));
QEventLoop loop;
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
QTimer timer;
connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
timer.start(5000);
loop.exec();
QByteArray result = reply->readAll();
if (reply->error()!=QNetworkReply::NoError)
{
qDebug() << "Request failed:" << reply->errorString();
return false;
}
else
{
qDebug() << "Reply from gribserver: " << result;
}
Well, these questions sound pretty stupid but I just can't figure it out how the sourcecode should look like. Any help would be apprechiated.
Cheers
Kars