The story is about QObject::connect and threads. So in this scenario you should never use Qt::DirectConnection. quit is called in thread B, it is possible that quit is called before exec and thread A is going to sleep forever. If you change it to Qt::DirectConnection, the story is different. Your second example works fine because QObject::connect is the same, too. Therefore, your first example always runs correctly because the signal and slot are connecting together using Qt::QueuedConnection (from default value Qt::AutoConnection). This is exactly what we want and everything works fine. In other words, quit is invoked only when exec is running. The slot myLoop.quit is invoked when control returns to the event loop, myLoop.exec. The slot is executed in the receiver's thread. The slot is invoked when control returns to the event loop of the receiver's thread. The signal is emitted in thread B and the receiver myLoop is in thread A, that means you are using Qt::QueuedConnection: (Default) If the receiver lives in the thread that emits the signal, Qt::DirectConnection is used. But how? Take a look at QObject::connect, the last argument is Qt::ConnectionType type = Qt::AutoConnection MyLoop.quit must be called after thread A is sleeping, otherwise thread A may sleep forever because quit may be called before sleeping. This function says when finished() is emitted, myLoop.quit() should be called just after the event occurs. The key is QObject::connect: QObject::connect(x, SIGNAL(finished()), &myLoop, SLOT(quit())) I hope I was able to transport my question to be understandable by experts. But from which event loop? invokeMethod() is not told to invoke the method in a particular event loop (myLoop), so why should the event posted to myLoop instead into the "outer" loop? In fact, myLoop is not even running at that time. I understand, that in this case doTheJob is called from the event loop. QMetaObject::invokeMethod(x, "doTheJob", Qt::QueuedConnection) I have been told by a collegue, that I could use QEventLoop myLoop What happens, when it emits already "finished", before myLopp is started? When a new instance of QEventLoop is just created, does it automatically mean, that signals emitted from myLoop are automatically handled within that new handler? Moreover, the loop starts some while after having started the job. Will that work? According to some other postings around - it should. * x is asnchrounous and will emit "finished" when ist job is done */ QObject::connect(x, SIGNAL(finished()), &myLoop, SLOT(quit())) I want to use that in a blocking way: QEventLoop myLoop In order to do the internals, I have to use an asynchronous class, emmiting a signal when it has finished its job in the background. I want to implement a method, which "blocks" until the handling is finished (for what reason ever.). My question might appear as somehow "ragged" and I want to apologize for that in advance. Highest difficulty rating day by day to Bitcoin but price remains 1 satoshi bc its spot price on FreiExchange is just that.I'm a pure Qt beginner and currently want to understand its basic concepts and how to use them in the right way. Problem is I can’t say its just the development and uniqueness that make the price of the project rise - because Im a dev with Devcoin - the 3rd alt ever, the most unique and alike genesis block (0) to Bitcoin’s genesis block - go look for it lol… and 10 years of consistent community and dev interaction with development rolled out consistently over time. I still don’t get the reason for these pumps, but I do love the project. Even if it goes down it will go up again and beyond this. It’ll take another 10.6 hours to deposit on TO. I tried sending a small amt of WOW for a rare sell (I never sell anything I hodl) in attempt to get some good profit to reinvest when it goes back down and here I am - I just calculated at the rate of my first 4 conf.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |