Results 1 to 8 of 8

Thread: Event queue size

  1. #1
    Join Date
    Nov 2010
    Posts
    28
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Event queue size

    hi,

    is it possible to see the event queue for a given object?

    I want to be able to know if I send too many events, and then drop some.

  2. #2
    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: Event queue size

    Objects don't have their own event queues. There is one event queue per thread for all objects living in that thread. And as far as I know there is no way of removing events from the queue without processing them.
    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.


  3. #3
    Join Date
    Nov 2010
    Posts
    28
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Event queue size

    Thanks for your answer.

    What i want is the event queue size for a given THREAD, you're right

    But I don't want to remove events, but just not send them. To know if i must not send an evnet, i need to know the event queue size for the thread i want to send it.

    is is possible?

  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: Event queue size

    Quote Originally Posted by naroin View Post
    What i want is the event queue size for a given THREAD, you're right

    But I don't want to remove events, but just not send them. To know if i must not send an evnet, i need to know the event queue size for the thread i want to send it.
    Hmm... so, let's say the event loop has 10 events pending, does it give you any meaningful information? You don't know what events are they...

    Please state what you need this functionality for, there is probably an easier way to do what you want.
    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
    Nov 2010
    Posts
    28
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Event queue size

    I've got something like a server that receive lots of "items".

    For each item, i have to make different actions, for instance saving it into database, or do some calculations on it. So i have a thread "db" and a thread "calculate".
    If the db is slow, there's a risk that i send too many items to it while they are not treated in time, and then the application will crash.
    So i want to drop some items : do not send it to the thread that is too charged.

  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: Event queue size

    And how is the size of event loop going to help you with this? Do the following instead:
    Qt Code:
    1. QMutex mutex;
    2.  
    3. struct Job {
    4. Something data;
    5. QDateTime timeToLive;
    6. };
    7.  
    8. QQueue<Job> queue;
    9.  
    10. class DatabaseHandler : public QThread {
    11. public:
    12. void run() {
    13. ... = QSqlDatabase::addDatabase(...);
    14. // ...
    15. mutex.lock();
    16. while(cond.wait(&mutex)) {
    17. mutex.lock();
    18. while(!queue.isEmpty()){
    19. Job job = queue.dequeue();
    20. mutex.unlock();
    21. if(job.timeToLive >= QDateTime::currentDateTime()) {
    22. processJob(job);
    23. }
    24. mutex.lock();
    25. }
    26. }
    27. // ...
    28. QSqlDatabase::removeDatabase(...);
    29. }
    30. };
    To copy to clipboard, switch view to plain text mode 

    Write the other end of the communication yourself. Oh, and provide a stop condition for the thread.
    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
    Nov 2010
    Posts
    28
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Event queue size

    I wanted to do that with signals & slots, but yes, your solution is good.

    Thanks a lot

  8. #8
    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: Event queue size

    Signals and slots are not an ultimate solution to everything. There is no point in using signals and slots if the emitting object apriori expects a particular object and particular slot of that object to respond to this signal. You can instead trigger the functionality directly since the objects are tightly coupled anyway.
    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. What's the size of Qt event queue?
    By ShaChris23 in forum Qt Programming
    Replies: 3
    Last Post: 6th November 2009, 17:54
  2. How to peek at the Event queue?
    By TheRonin in forum Qt Programming
    Replies: 3
    Last Post: 7th May 2009, 14:21
  3. Qt event queue overloading?
    By gct in forum Qt Programming
    Replies: 3
    Last Post: 17th March 2008, 18:39
  4. Event Queue Question
    By TheGrimace in forum Qt Programming
    Replies: 10
    Last Post: 5th October 2007, 16:55
  5. Cannot queue...
    By vratojr in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2006, 15:06

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.