Hedede
Hedede

Reputation: 1173

Calling QApplication::processEvents from a slot causes same slot to be called again

There is a signal some_signal which is connected to a slot on_some_signal using a queued connection. Like this:

connect(this, SIGNAL(some_signal()), receiver, SLOT(on_some_signal()), 
        Qt::QueuedConnection|Qt::UniqueConnection);

The on_some_signal calls some heavy machinery inside of which QApplicaton::processEvents is called. When QApplicaton::processEvents is called, it triggers the same slot again.

Question is, how to prevent the slot from being called twice? The signal is emitted only once.

Upvotes: 1

Views: 456

Answers (1)

Swift - Friday Pie
Swift - Friday Pie

Reputation: 14589

It's expected behaviour. QApplicaton::processEvents invokes mechanisms that fall asynchronous handlers (slots). Essentially your slot was called from inside of that mechanism, and it would call all unprocessed events again, starting with itself. Its purpose to be called from inside of thread, not from slot handlers.

Upvotes: 3

Related Questions