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.
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.
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.
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?
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.
And how is the size of event loop going to help you with this? Do the following instead:
Qt Code:
QMutex mutex; QWaitCondition cond; struct Job { Something data; QDateTime timeToLive; }; QQueue<Job> queue; public: void run() { // ... mutex.lock(); while(cond.wait(&mutex)) { mutex.lock(); while(!queue.isEmpty()){ Job job = queue.dequeue(); mutex.unlock(); processJob(job); } mutex.lock(); } } // ... } };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.
I wanted to do that with signals & slots, but yes, your solution is good.
Thanks a lot
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.
Bookmarks