QThread and pointers
-
wrote on 26 Apr 2016, 08:54 last edited by
CreateMembers() is called after i moved the workobject to the thread.
The connection type is set to Qt::AutoConnection.
Yes, i need them in some other slots again.
-
Then it should be OK.
The slot is executed in the thread where the object resides, so the objects are created in the same thread.
Regarding sharing the pointers with other objects: in which thread are those other objects? -
wrote on 26 Apr 2016, 09:25 last edited by beecksche
The other objects are also created in the createMembers() slot.
So i can use the shared pointers in the other objects safely, because the objects "live" in the same thread, right?
-
CreateMembers() is called after i moved the workobject to the thread.
The connection type is set to Qt::AutoConnection.
Yes, i need them in some other slots again.
@beecksche said:
CreateMembers() is called after i moved the workobject to the thread.
It makes a whole lot of difference how you call it. Is it connected to a signal, do you call it explicitly?
-
wrote on 26 Apr 2016, 11:27 last edited by
Sorry, i haven't told you yet. It's connected to a signal!
-
@beecksche
Then it's perfectly fine. -
wrote on 26 Apr 2016, 11:32 last edited by
Perfect, thanks a lot!
-
@beecksche
No worries.
Although,QScopedPointer
might be appropriate here (looking at your code), you may want to check it out. -
wrote on 26 Apr 2016, 11:47 last edited by beecksche
The advatage of a QScopedPointer is that you don't have to care about the destruction of the object, right?
The object will be destroyed when the pointer is out of scope? -
The advatage of a QScopedPointer is that you don't have to care about the destruction of the object, right?
The object will be destroyed when the pointer is out of scope?@beecksche said:
The advatage of a QScopedPointer is that you don't have to care about the destruction of the object, right?
Yes. It's a thin wrapper around the raw pointer and will
delete
the held reference when it goes out of scope. The idea is to use the stack basedQScopedPointer
object to manage the heap-allocated object it's referencing.Kind regards.
12/12