Results 1 to 8 of 8

Thread: Synchronous HTTP requests and QEventLoop

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: Synchronous HTTP requests and QEventLoop

    Quote Originally Posted by bssldr View Post
    Question: is there a nicer way to achieve this?
    Apart from wrapping it all in a single call, no.

    Another question: is it possible to create an event loop that allows you to manually post events to it?
    You don't post events to event loops but rather to objects. QEventLoop is such an object too of course but I can't think of a use case where you'd want to post an event to an event loop object.
    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.


  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: Synchronous HTTP requests and QEventLoop

    I can't think of a way thats nicer from what you want to do.

    QNetworkAccessManager was designed to be asynchronous. Why anyone would want a synchronous version is a little odd to me, but to each there own.

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

    Default Re: Synchronous HTTP requests and QEventLoop

    Here is an example that uses a synchronous request.

    A system can issue requests to services X, Y, and Z over the network at user request. If this is the first time in a program run that an operation is requested then the system must first request a "login" (L) of the user with the service provider before completing the operation X, Y, or Z. L must complete entirely before operation X, Y, or Z is continued because a cookie returned by L must be available during X, Y, or Z. If the operation X, Y, or Z fails because the cookie has expired or been otherwise rejected by the service provider (perhaps they reboot a server) then the L process must be completed followed by a repeated X, Y, or Z.

    The L process looks like a classic synchronous request. What is the cleanest wholly asynchronous way to achieve this?

  4. #4
    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: Synchronous HTTP requests and QEventLoop

    Quote Originally Posted by ChrisW67 View Post
    What is the cleanest wholly asynchronous way to achieve this?
    I'd say a state machine plus a signal emission upon detection of a failed request due to session timeout. It's nothing difficult but I agree there are situations when doing things synchronously simplifies matters greatly.
    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.


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

    Default Re: Synchronous HTTP requests and QEventLoop

    Good Morning Wysota,

    Do you ever sleep?

    I've just stocked up on caffeine to explore the state machine machine approach to something like the the scenario above with few extra quirks. I've not used QStateMachine in anger so this should be an interesting morning.

  6. #6
    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: Synchronous HTTP requests and QEventLoop

    Quote Originally Posted by ChrisW67 View Post
    Good Morning Wysota,
    Good morning

    Do you ever sleep?
    If I don't suffer from insomnia or don't have deadlines for the next day then in general - yes.

    I've just stocked up on caffeine to explore the state machine machine approach to something like the the scenario above with few extra quirks. I've not used QStateMachine in anger so this should be an interesting morning.
    By saying "state machine" I didn't exactly mean QStateMachine although of course it can be used here as well, it's just sometimes it's an overkill to use it when a simple enum variable holding the state would suffice
    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 use QEventLoop?
    By MorrisLiang in forum Newbie
    Replies: 3
    Last Post: 13th May 2010, 16:23
  2. qprocess or qeventloop
    By knishaq in forum Qt Programming
    Replies: 1
    Last Post: 20th December 2009, 10:14
  3. Synchronous QFtp?
    By aarpon in forum Qt Programming
    Replies: 2
    Last Post: 26th October 2009, 09:28
  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. Synchronous Http (Good reason)
    By umbrella in forum Qt Programming
    Replies: 5
    Last Post: 4th April 2008, 14:14

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.