PDA

View Full Version : Qlist<pixmap> sembolList pass another class only via pointer.



sevketk
22nd December 2019, 17:54
I have QPixmaps array QList ,
mainwindow.h file


QList<QPixmap> sembolList;

mainwindow.cpp file


sembolList << QPixmap(":/images/9_maca.png");
sembolList << QPixmap(":/images/10_maca.png");
sembolList << QPixmap(":/images/11_maca.png");
...
...

I want to send another classes (more than one) as constructor parameter sembolList but not instance or copy , only use its adress . in other words , I do not want to take up space in memory. one time create and dynamically use all my class. How to make that?

d_stranz
23rd December 2019, 17:23
The QPixmap class is implemented with internal data sharing, so when you pass an instance of the class by value (as you are doing with QList< QPixmap >), the pixel data is -not- copied. So you can pass your QList<> by reference or by value. If you pass by value (QList<> mylist, instead of QList<> & mylist) then the only thing copied is the list itself. The QPixmap instances in the list are not copied, only their reference counts are incremented.

See the "Detailed Description" in the QPixmap documentation and the "Implicit Sharing" (https://doc.qt.io/qt-5/implicit-sharing.html) overview in the Qt Core documentation.