Results 1 to 4 of 4

Thread: signal getting caught in another event loop

  1. #1
    Join Date
    Apr 2011
    Location
    Hyderabad, India
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default signal getting caught in another event loop

    In my program i am using QHttp subclass for http requests. As QHttp does not provide blocking functions i m using local event loop to handle blocking functionality. I am connecting requestfinished() signal to a slot which will later quit th event loop.

    But in addition to that i have another class which also uses QHttp and there also requestfinished() signal is connected to some slot. This class is running in main event loop.

    Now wat happening is that when i started my local event loop from above class the signal is getting caught in main event loop instead of it getting caught in my local event loop. Wats the behavior of same signal and slots across different event loops in Qt. Is tat if same signals connected to some slots but in different eventloop, the signal may get caught in any of the event loop?

    To solve this problem is there any thing i can do or i have to use seperate thread for my need.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: signal getting caught in another event loop

    Signals dont get stuck in event loops. signals don't care about which event loop they enter. Slots tend to care a bit more, but signals... not so much.

    "Now wat happening is that when i started my local event loop from above class the signal is getting caught in main event loop instead of it getting caught in my local event loop"
    It wont make any difference. If the loops are in different threads, then you may have a problem stopping some slots from running (since slots only execute in their own thread when executed from a signal (normally)).

    "Wats the behavior of same signal and slots across different event loops in Qt"
    different event loops makes no difference if they're in the same thread.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Apr 2011
    Location
    Hyderabad, India
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signal getting caught in another event loop

    Ok amleto,

    So according to ur post what i understand is that signals dont care about event loops. A signal get generated and then a slot get fired; now which slot would get executed? If i initiated the request from my local eventloop then the slot in my local loop should get fired; but th slot in main event loop gettin fired. So does tat mean Slots also dont care about eventloops as they r in same thread.

  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: signal getting caught in another event loop

    Quote Originally Posted by raj_iv View Post
    This class is running in main event loop.
    There is only one event loop (per thread). QEventLoop only provides a different entry point to the existing event loop. Events do not care if they are handled as a result of QEventLoop::exec() or QCoreApplication::exec(). The only difference is that calling exec() on QEventLoop bumps up an internal level counter in the event loop which cares that deferred delete (aka QObject::deleteLater()) is executed on the same (or lower) level at which the delete was scheduled. In other words, if you do this:
    Qt Code:
    1. QObject *obj = ...;
    2. obj->deleteLater();
    3. loop.exec();
    4. bool b = obj->isStillThere();
    To copy to clipboard, switch view to plain text mode 

    "obj" is still valid after loop.exec() returns.
    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. The following user says thank you to wysota for this useful post:

    raj_iv (29th September 2012)

Similar Threads

  1. Replies: 25
    Last Post: 28th October 2011, 21:22
  2. Replies: 1
    Last Post: 22nd July 2010, 10:16
  3. event loop isStarted() signal?
    By Xerion in forum Qt Programming
    Replies: 1
    Last Post: 18th February 2008, 22:45
  4. signal and slot across threads having event loop
    By travis in forum Qt Programming
    Replies: 6
    Last Post: 6th November 2007, 00:56
  5. Replies: 4
    Last Post: 23rd January 2006, 17:51

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.