I have experience in programming but Im still learning, I decided to create a QVector array to store some QGraphicsRectItem in it like this:
QVector<QGraphicsRectItem> *FreeLayer1;
FreeLayer1 = new QVector<QGraphicsRectItem>;
FreeLayer1->resize(10);
Here is the error:
c:\QtSDK\Desktop\Qt\4.8.1\msvc2010\include\QtCore/qvector.h(532) : error C2248: 'QGraphicsRectItem::QGraphicsRectItem' : cannot access private member declared in class 'QGraphicsRectItem'
c:\qtsdk\desktop\qt\4.8.1\msvc2010\include\qtgui\qgraphicsitem.h(728) : see declration of 'QGraphicsRectItem::QGraphicsRectItem'
c:\qtsdk\desktop\qt\4.8.1\msvc2010\include\qtgui\qgraphicsitem.h(683) : see declaration of 'QGraphicsRectItem'
c:\QtSDK\Desktop\Qt\4.8.1\msvc2010\include\QtCore/qvector.h(473) : while compiling class template member function 'void QVector<T>::realloc(int,int)'
I know this may sound really stupid or really easy to do but I didn’t find errors exactly like mine and I don’t have a lot of experience with declarations. My question is how can I write this code in order to use my variable FreeLayer1. I insist on using QVector<>, I just don’t know how to declare it.
Thank you for your help! 🙂
Your declaration is fine, the problem seems to be that QGraphicsRectItem’s default constructor is private, so you can’t use methods of QVector which need the default constructor, like QVector::resize. Looking at the docs for QGraphicsRectItem, there seems to be no public copy constructor or copy assignment operator either, so QGraphicsRectItem is not eligible as the element type of QVector. You’ll have to store pointers to QGraphicsRectItem: