PDA

View Full Version : Copying QList



frenk_castle
26th November 2009, 21:41
Ok. I have a class.



class Material : public QObject
{
public:
Material(QObject *parent = 0);

protected:
int m_count;
QString m_fisName;
QString m_fisCode;
QString m_name;
QString m_nameAux;
};


I made a typedef



typedef QList<Material> MaterialList;


I have another class



class RegularOrder : public Order
{
public:
RegularOrder(QObject *parent = 0);

void TwinList(MaterialList twinList);
void P3110List(MaterialList p3110List);
void CPSList(MaterialList cpsList);
void KernList(MaterialList kernList);
void BurhList(MaterialList burhList);
void ManualList(MaterialList manualList);

protected:
QList<Template> m_templateList;
int m_currentTemplateIndex;

UseFlag m_listFlag;
int m_listCount;
QString m_deliveryWhole;

MaterialList m_twinList;
MaterialList m_p3110List;
MaterialList m_cpsList;
MaterialList m_kernList;
MaterialList m_burhList;
MaterialList m_manualList;

QList<JobProperties> m_jobPropertiesList;
};


which is so far implemented like this



RegularOrder::RegularOrder(QObject *parent) : Order(parent)
{
}

void RegularOrder::TwinList(MaterialList twinList)
{
m_twinList = twinList;
}

void RegularOrder::P3110List(MaterialList p3110List)
{
m_p3110List = p3110List;
}

void RegularOrder::CPSList(MaterialList cpsList)
{
m_cpsList = cpsList;
}

void RegularOrder::KernList(MaterialList kernList)
{
m_kernList = kernList;
}

void RegularOrder::BurhList(MaterialList burhList)
{
m_burhList = burhList;
}

void RegularOrder::ManualList(MaterialList manualList)
{
m_manualList = manualList;
}


When I try to compile I get the following messages:

/home/ivan/Development/Qt/Radni Nalog/WorkOrder/woidl.cpp:1: In file included from woidl.cpp:1:
/home/ivan/Development/Qt/Radni Nalog/WorkOrder/woidl.h:14: instantiated from ‘void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = Telekom::WorkOrder::Material]’
/home/ivan/Development/Qt/Radni Nalog/WorkOrder/woidl.h:14: instantiated from ‘void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = Telekom::WorkOrder::Material]’
/home/ivan/Development/Qt/Radni Nalog/WorkOrder/woidl.h:14: instantiated from ‘void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = Telekom::WorkOrder::Material]’
/home/ivan/Development/Qt/Radni Nalog/WorkOrder/woidl.h:14: instantiated from ‘void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = Telekom::WorkOrder::Material]’
/home/ivan/Development/Qt/Radni Nalog/WorkOrder/woidl.h:14: instantiated from ‘void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = Telekom::WorkOrder::Material]’

Basically the compile stops at the m_twinList = twinList line of code. I read somewhere that QObject can't be used as a reference and copied as normal because of something but honestly didn't understand it completely.

I solved the problem by removing the inheritance of QObject in Material class. I made it independent. Now I only sort of needed that because I could make some other object a parent of the material class instances so I would have to worry about deleting it. My program will work just fine with out this parenting because only RegularOrder class will be instantiated and only RegularOrder class will need a parent to look after it. But could somebody explain to me what exactly happened here so I know for the future.

Thanks.

squidge
26th November 2009, 22:47
Check the documentation for Q_DISABLE_COPY 'Instances of subclasses of QObject should not be thought of as values that can be copied or assigned, but as unique identities.'

Whether or not this is why you are getting the error I don't know, I just remember reading it.

frenk_castle
26th November 2009, 23:59
Well I found some explanations in the QObject documentation. Now it is clearer to me what I tried to do and why it didn't work that way.

wysota
27th November 2009, 00:48
You don't need Material to be a QObject anyway, so you can safely get rid of that ancestor.