Results 1 to 4 of 4

Thread: Http request

  1. #1
    Join Date
    Aug 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Http request

    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

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Http request

    Quote Originally Posted by kars View Post
    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.
    Curious, the latest released Qt is 4.7.3. It's unlikely to have a bearing on this problem though.
    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.
    The standard socket connect(), declared in sys/socket.h, and QObject::connect() are two different beasts. If you are using the Qt classes to do this transfer then you should not need the low-level socket code at all, i.e. remove "#include <sys/socket.h>'

    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?
    If the application code you started with was complete then it should already have that. Look for main() and it will probably look like:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QCoreApplication app(argc, argv);
    4.  
    5. // some object creation
    6.  
    7. return app.exec(); // the event loop
    8. }
    To copy to clipboard, switch view to plain text mode 
    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.
    The docs for Qt a pretty good. You could start by looking at Network Examples
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  3. #3
    Join Date
    Aug 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Http request

    Hi Chris

    Tanks for your answers... I've got it working finally
    Yesterday I installed QT at my CPU and the Qt Creator About screen really says the following:
    Qt Creator 2.2.1
    Based on Qt 4.7.4 (32 bit)
    Built on Jun 15 2011 at 16:37:12

    Cheers
    Karsten

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Http request

    It means Creator is based on Qt 4.7.4 (which is quite normal as it always uses prereleases of Qt) and not the application.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to make a HTTP request in QTJambi
    By divanshu in forum Newbie
    Replies: 2
    Last Post: 28th June 2011, 06:29
  2. HTTP request POST in QT application
    By abdul_moiz in forum Newbie
    Replies: 5
    Last Post: 24th June 2011, 03:48
  3. HTTP request
    By Trok in forum Qt Programming
    Replies: 9
    Last Post: 5th January 2010, 14:49
  4. problem with Synchronous Http request
    By rchaitanya in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 30th January 2009, 11:03
  5. http request
    By yagabey in forum Qt Programming
    Replies: 3
    Last Post: 28th December 2008, 19:19

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.