Post events before exec causes lost connects
- 
I have created a simple, single thread, app in Qt6. My sole class creates a couple of timers and prints a qDebug message in the timeout slot. These messages never print. My class is created before the app.exec() in main, so before the event loop is executed. I suspect this is related. If I create QTimers, and connect the timeout signal before the event loop exec is called, are my signals-slots lost once exec is called? If so, what's the right way to handle this? Note: This question is about use of QTimer & Eventloop. Not looking for help with specific code. (i.e. theory) 
- 
I have created a simple, single thread, app in Qt6. My sole class creates a couple of timers and prints a qDebug message in the timeout slot. These messages never print. My class is created before the app.exec() in main, so before the event loop is executed. I suspect this is related. If I create QTimers, and connect the timeout signal before the event loop exec is called, are my signals-slots lost once exec is called? If so, what's the right way to handle this? Note: This question is about use of QTimer & Eventloop. Not looking for help with specific code. (i.e. theory) @ocgltd said in Post events before exec causes lost connects: If I create QTimers, and connect the timeout signal before the event loop exec is called, are my signals-slots lost once exec is called? No. You are supposed to set up with connect()s before the event loop is called withexec(), that's fine. If an event arrived before the loop is entered that might be a different situation, but that is not what you say.If your situation is as simple as you say you should produce a standalone example. 
- 
@ocgltd said in Post events before exec causes lost connects: If I create QTimers, and connect the timeout signal before the event loop exec is called, are my signals-slots lost once exec is called? No. You are supposed to set up with connect()s before the event loop is called withexec(), that's fine. If an event arrived before the loop is entered that might be a different situation, but that is not what you say.If your situation is as simple as you say you should produce a standalone example. As @JonB said, the debug messages must be printed, if coded correctly. 
 Please post your code.
- 
 O ocgltd has marked this topic as solved on O ocgltd has marked this topic as solved on
- 
After some testing I can confirm events (signals) are queued up and once .exec() is called those events are processed. Calling connect before .exec() always works fine. I think I was thrown by some old/wrong posts that posting events/connects before the event loop starts are lost. 
 

