Results 1 to 8 of 8

Thread: Clearing the signal queue

  1. #1
    Join Date
    May 2010
    Posts
    30
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Clearing the signal queue

    Hey All,

    I have two signals that get emitted occasionally:

    Load()
    Unload()

    These are connected with corresponding slots in a worker thread that will grab required data.
    Is there a way, from the emitting function, to clear any Unload() signals from the signal queue? If it is not possible to clear just the unloads, is it possible to clear the entire queue?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Clearing the signal queue

    You can disconnect signals and slots just like you connect them using QObject::disconnect();

  3. #3
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Clearing the signal queue

    Once signals have been emitted, I don't know of any way to "recall" them. You could probably simulate such functionality through the use of, say, a global variable or singleton that would be set to a value indicating that no more signals should be processed, which the receiver would check at the beginning of each function call. Depending on the details of your implementation, it might be possible to send such information along with each signal itself instead of using a global.

    As already noted, you can disconnect signals and slots, but that won't purge any signals that have already been sent.

  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: Clearing the signal queue

    This situation is not well suited for signals and slots. If you expect exactly one receiver for a signal and you know the receiver upfront then why not interact with it directly? Either post an event to the other object or implement some kind of a message queue between two objects.
    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
    May 2010
    Posts
    30
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Clearing the signal queue

    "If you expect exactly one receiver for a signal and you know the receiver upfront then why not interact with it directly?"

    Signals, or events (I consider them equivalent when using a queued connection across threads) give me a simple means of passing information from my main thread to my worker thread. The problem I have is that the user can obsolete previously sent commands before the worker has had time to process them. Is it easier to clear out posted events than it is to clear a signal queue? Is there another message queuing structure within QT that would do a better job at what I am trying to do, or should I look at 3rd party libraries?

  6. #6
    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: Clearing the signal queue

    Quote Originally Posted by grabalon View Post
    Is it easier to clear out posted events than it is to clear a signal queue?
    Physically yes, logically no. You can send (not post but send) an event to the other thread to order it to ignore some other events. Of course you have to implement that all and you have no guarantees whether the other thread didn't manage to process those events in the meantime.
    Is there another message queuing structure within QT that would do a better job at what I am trying to do, or should I look at 3rd party libraries?
    Does everything have to be given on a silver platter? Can't you use QQueue with a mutex or other similarily simple solution?
    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.


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

    Default Re: Clearing the signal queue

    What you need is to call methods directly which directly manage a list, then you have full control.

    eg. in your header file:
    Qt Code:
    1. QReadWriteLock listlock;
    2. QList<myListType*> list;
    To copy to clipboard, switch view to plain text mode 

    then, in an append method:
    Qt Code:
    1. listlock.lockForWrite();
    2. list.append(foo);
    3. listlock.unlock();
    To copy to clipboard, switch view to plain text mode 

    then you can have clear method, private read method, etc.

    [This is only an example, there are lots of other ways to do it]

  8. The following user says thank you to squidge for this useful post:

    grabalon (20th May 2010)

  9. #8
    Join Date
    May 2010
    Posts
    30
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Clearing the signal queue

    The list idea is exactly what I need. Thanks to all for your help.

Similar Threads

  1. help regarding queue
    By aj2903 in forum Qt Programming
    Replies: 1
    Last Post: 3rd April 2009, 07:48
  2. QQueue vs STL queue
    By Lele in forum Qt Programming
    Replies: 3
    Last Post: 8th November 2007, 17:35
  3. clearing lineEdits
    By Salazaar in forum Newbie
    Replies: 4
    Last Post: 4th June 2007, 21:02
  4. Clearing QDateEdit
    By jpujolf in forum Qt Programming
    Replies: 3
    Last Post: 27th July 2006, 21:19
  5. Cannot queue...
    By vratojr in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2006, 15:06

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.