Results 1 to 7 of 7

Thread: QHttp RequestStarted does not even begin!

  1. #1
    Join Date
    Jul 2007
    Posts
    30
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Question QHttp RequestStarted does not even begin!

    I set up my project, using QT += network

    It's a static app and I included QtNetwork.

    I made sure all the connections are connected... no problems there...

    Qt Code:
    1. connect(http, SIGNAL(stateChanged(int)), this, SLOT(DisplayProgress(int)));
    2. connect(http, SIGNAL(requestFinished(int, bool)), this, SLOT(httpRequestFinished(int, bool)));
    3. connect(http, SIGNAL(requestStarted (int)), this, SLOT(httpRequestStarted(int)));
    4. connect(http, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int)));
    5. connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)), this, SLOT(readResponseHeader(const QHttpResponseHeader &)));
    To copy to clipboard, switch view to plain text mode 

    Neither get(), nor post() has any problem executing. But after that everything seems to go silent.

    Like as if the signals aren't working at all.

    I put logs everywhere, and not a single connected signal is being emitted. requestStarted doesn't even begin.

    I made sure to follow the example in QHttp. I simply put up a GET for a PHP page online. I am online, firewall is off and everything (though it is vista).

    Qt Code:
    1. void httpRequestStarted(int id){
    2. if(id == httpPostId){
    3. Log2("Started");
    4. } else if (id == httpGetId){
    5. Log2("Started");
    6. }
    7. Log2("Req Started");
    8. }
    To copy to clipboard, switch view to plain text mode 

    But nothing is getting logged.
    Apparently, either QtNetwork isn't working, or neither get nor post activates httpRequestStarted.

    I declared http as a QHttp(this) (this being a QObject class).

    The logs just stop here and here:
    Qt Code:
    1. void cConnect::PostRead(QString data, const QString& siteurl, int encrypt){
    2. //data = Encrypt(data);
    3. httpRequestAborted = false;
    4. httpPostId = http->post(QUrl::toPercentEncoding(siteurl), data.toAscii());
    5. }
    To copy to clipboard, switch view to plain text mode 

    This is for GET:
    Qt Code:
    1. httpRequestAborted = false;
    2. httpGetId = http->get(QUrl::toPercentEncoding(Url), file);
    3. Log2("CC::Downloading File");
    To copy to clipboard, switch view to plain text mode 

    How can this be? I never declared a "Host" and I never get the signal for requestStart().
    Last edited by Arsenic; 7th August 2008 at 22:14.

  2. #2
    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: QHttp RequestStarted does not even begin!

    Are you running the event loop (for instance by calling QApplication::exec())?

  3. The following user says thank you to wysota for this useful post:

    Arsenic (9th August 2008)

  4. #3
    Join Date
    Jul 2007
    Posts
    30
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QHttp RequestStarted does not even begin!

    In another file, I am running exec(), it's not a threaded app.

    Also, I recently tried to see if simply setHost() is working, but even that doesn't work. No signals emitted.

    However, signals are emitted in another test app i compiled.. So weird.

    Also, when I immediately (not in any slot or signal), right after setHost, I typed:
    http->errorString().toLocal8Bit().constData() for my log.
    It says "Unknown Error". Shouldn't it say "No Error"?

    At some point I did receive signals, but then they disappeared, I can't reproduce them.

  5. #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: QHttp RequestStarted does not even begin!

    Can you prepare a minimal compilable example reproducing the problem?

  6. #5
    Join Date
    Jul 2007
    Posts
    30
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QHttp RequestStarted does not even begin!

    Well, when I opened the HTTP example inside my Qt directory, it wasn't working, some sort of missing dynamic link in qtnetwork.

    Then, I took the code, put it in a different folder, compiled it myself, to see if my static compiled Qt works properly. And the HTTP downloader works nicely.

    So my environment should be fine.

    I even tried compiling http.exe as static, it worked fine too. It means that it must be something in my code maybe.

    But I did everything, I triple checked all the codes, compared it with other http programs including your own. What are possible causes of signals not being emitted?

  7. #6
    Join Date
    Jul 2007
    Posts
    30
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QHttp RequestStarted does not even begin!

    double post.

  8. #7
    Join Date
    Jul 2007
    Posts
    30
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QHttp RequestStarted does not even begin!

    Ok I figured it out.

    You were right the first time wysota.

    See I do have an application running as app.exec(), but what I later meditated and figured out was, that if you have a program that works and then a function calls a new class (which does the HTTP work), then that new class returns, and then the function ends. And my problem was, I declared the class as a local object and it was on the local stack, so as soon as that function returned as well, the HTTP class never got a chance to run long enough to create signals etc... As soon as I changed the local object to a pointer object that runs throughout the main class, it worked perfectly.

    Thanks.

Similar Threads

  1. From QHttp to QHttp over SSL
    By Nyphel in forum Newbie
    Replies: 1
    Last Post: 3rd July 2007, 10:41

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.