Results 1 to 16 of 16

Thread: trying to make QHttp synchronous or threaded

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: trying to make QHttp synchronous or threaded

    By the way... This:
    Qt Code:
    1. while(!someFlagActive) qApp->processEvents();
    To copy to clipboard, switch view to plain text mode 
    is equivalent to this (just designed worse :P):
    Qt Code:
    1. QHttp *http;
    2. //...
    3. connect(http, SIGNAL(done(bool)), &loop, SLOT(quit())); // you can use a different signal here
    4. loop.exec(QEventLoop::AllEvents|QEventLoop::WaitForMoreEvents);
    5. doSomethingAfterDoneIsEmitted();
    To copy to clipboard, switch view to plain text mode 
    Remember that done() will be processed before the loop exits!

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

    ber_44 (19th April 2007)

  3. #2
    Join Date
    Apr 2007
    Posts
    46
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    4

    Default Re: trying to make QHttp synchronous or threaded

    > probably "reqId.value(reqId_)" returns an invalid value

    No, I printed it, it's just fine. The crash was caused by something else... Now I'm just getting
    free(): invalid pointer 0x40016ca0!
    after returning from the SET_HOST / SET_USER case (request is queued to happen after HttpWindow::HttpWindow()

    But this does not bother me too much. My program goes on to the first download, BUT when I print file->bytesAvailable() in the GET_N_BYTES case it is zero-size. However, the file does get downloaded just fine, as I see it after the program finishes.

    > If you want to force "synchronousness", use a busy loop
    > QEventLoop loop;
    > connect(http, SIGNAL(done(bool)), &loop, SLOT(quit())); // you can use a different signal here
    > loop.exec(QEventLoop::AllEvents|QEventLoop::WaitFo rMoreEvents);
    > doSomethingAfterDoneIsEmitted();

    That seems to be the solution. IMHO we just replaced the original idea of using QThread::wait() with a local event loop (the program won't execute the next statement until that local event loop has finished).
    Last edited by ber_44; 16th April 2007 at 02:59.

Similar Threads

  1. Window OS make distclean && qmake && make one line
    By patrik08 in forum General Programming
    Replies: 4
    Last Post: 22nd March 2007, 10:43
  2. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 05:57

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
  •  
Qt is a trademark of The Qt Company.