[SOLVED]What can I get using qApp->thread()
I am a newbie learning programming in Qt.
Not sure if my understanding is right: the qApp->thread() returns the main thread?
I encountered this sentence as below,
does this mean to move object to main thread? If not, what does this command do?
Hi @Felicity ,
Here is clear explanation .
Hi @Ni.Sumi ,
Actually I googled that post before asking this question; and no correct answer was chosen in that post.
I know what is Qt::ConnectionType, and understand how to move an object to a different thread other than the main thread, but have no idea what is qApp->thread().
Could you please explain something about qApp->thread() ?
qAppis a shorthand macro). While usually
QCoreApplication(and its descendants) are created in
main()and this is the recommended way of doing things, this may not always be the case. Now, when you create the application object, it creates a "fake" thread. By "fake" I mean that it creates a
QThreadobject that is representative of the thread in which the application object was created, but it's not started/run as a new thread. It's used for "bookkeeping" of the
QObjectinstances "live" in a thread (also referred to as "thread affinity" in the docs), and it's relevant what
QObjectbelongs to what thread when having signal-slot invocations.
So, the answer to your question is: Yes! It is the main thread.
As for this:
You can see that code in a thread different from the main/gui thread. It pushes the object back to the main thread (objects can only be "pushed" into a thread, but can't be "pulled" from another).
Thank you so much!
You explained everything!