Results 1 to 8 of 8

Thread: Clearing the signal queue

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 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.


  2. #2
    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?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 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.


  4. #4
    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]

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

    grabalon (20th May 2010)

  6. #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

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