⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)
How to track down detaching of QImage
alan73 last edited by
Is there a way to track down when QImage is doing detaching (full copy of data, implicit shared paragidm)? Motivation is that I've found out a lot of memcpy() calls while analyzing performance and now I'm going to find out in what places of my code I use QImage wrong way that causes detaching.
You'd need to modify Qt code to print some message when detach happens. But you will get a lot of these messages, as implicit sharing is used everywhere (all container classes, plus many more general Qt classes). You can use clazy tool to get some hints of inefficient use of shared classes, I think.
One good rule of thumb is - if you pass QImage (or any other implicitly shared class) into a function, always use const reference:
void someMethod(const QImage &image);
Also, be careful when using ranged for loop, it can detach if container is not const.