Question

I read here that the QVector class uses implicit data sharing to maximize resource usage and minimize copying. I don't know if emitting a signal with a QVector parameter to a slot in a different thread causes data copy or not! These questions also relate to this issue:

Passing QVector from worker thread to main thread via signal/slot

Emitting QVector reference in Qt signal results in copy

But i could not get the point from those. clearly my question is:

I have a signal :

void someSignal(QVector<int> values);

And a slot :

void someSlot(QVector<int> values);

These are in different threads and I connect them. so the connection type is Qt::QueuedConnection. Also i should state that the QVector elements are not modified in the slot. They are just read.

Does emitting the signal cause the QVector elements be copied?

Was it helpful?

Solution

Does emitting the signal cause the QVector elements be copied?

No. The implicit sharing documentation is also clear about it:

Implicit sharing takes place behind the scenes; the programmer does not need to worry about it. Even in multithreaded applications, implicit sharing takes place, as explained in Threads and Implicitly Shared Classes.

Just to highlight the first paragraph from that part of the documentation:

Qt uses an optimization called implicit sharing for many of its value class, notably QImage and QString. Beginning with Qt 4, implicit shared classes can safely be copied across threads, like any other value classes. They are fully reentrant. The implicit sharing is really implicit.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top