Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to write entire QVector to a binary file?
@J-Hilk Thanks, one thing which I am not sure about: What would happen if I use
const QVector<double>&instead of
QVector<double>, will it still copy the data if the connection type is
Qt:QueuedConnectionor will it just copy the reference for the vector?
KroMignon last edited by KroMignon
will it still copy the data if the connection type is Qt:QueuedConnection or will it just copy the reference for the vector?
In short: Yes they will be copied.
For more details take a look at this => https://www.embeddeduse.com/2013/06/29/copied-or-not-copied-arguments-signals-slots/
@KroMignon Thanks :)
JonB last edited by
The conclusion from the above results is that we should pass arguments to signals and slots by const reference and not by value. This advice is true for both direct and queued connections. Even if the sender of the signal and the receiver of the slot are in different threads, we should still pass arguments by const reference.
If you have both signal & slot declared with
QVector<double> vecand you change both to have
const QVector<double>&, you reduce 3 copies to 1.
Having said that: I do get lost as to what gets copied, aren't we only talking about the
QVectorstructure and not the data it references??
@JonB If it's a copy then I assume it is always going to be the data because the structure is not that significant in terms of memory usage, but I am not sure about it either.
If it's a copy then I assume it is always going to be the data
No, because Qt containers use copy-on-write. See https://doc.qt.io/qt-5/implicit-sharing.html