[Qt-interest] How to "snapshot" a QObject if it can't be copied?
David Walthall
walthall at wavefun.com
Fri Oct 16 18:42:19 CEST 2009
Hostile Fork wrote:
> Hi all...
>
> I have a QObject-derived class. It has signals and slots that modify
> the object's data in a multithreaded environment. (Yeah, yeah, who
> doesn't?) :)
>
> I'd like to be able to snapshot that object. Because certain routines
> would be harmed by getting different answers from method calls on this
> QObject (if modifications happen on the other thread while they are
> working). So routines have a QObject pointer, they call snapshot(),
> then they make all their method calls on the snapshot. That way they
> don't see the modifications.
It sounds like what you actually need is a mutex. If you need an object
to be unchanged during an operation, use a mutex to protect the object.
In fact, if you can modify an object in one thread while accessing it
in another thread, you need a mutex.
David
More information about the Qt-interest-old
mailing list