When compiling I get the following error, in QList . I'm using Qt 5.6.
error: use of deleted function 'Vitamin: Vitamin (const Vitamin &)' current-> v = new T (* reinterpret_cast (src-> v))
error: use of deleted function 'Vitamin: Vitamin (const Vitamin &)' new (current) T (* reinterpret_cast (src))
error: use of deleted function 'Vitamin: Vitamin (const Vitamin &)' else if (QTypeInfo :: isComplex) new (n) T (t);
error: use of deleted function 'Vitamin & Vitamin :: operator = (const Vitamin &) 'else * reinterpret_cast (n) = t;
BaseClass
Header
#ifndefCOMPONETNUTRITIONAL#defineCOMPONETNUTRITIONAL#include<QObject>#include<QList>classComponentNutritional:publicQObject{Q_OBJECTpublic:explicitComponentNutritional(QObject*parent=0);~ComponentNutritional();QStringgetName();floatgetValue();floatgetDairyValue();QStringgetMeasure();protected:QStringname;floatvalue;floatdairyvalue;QStringmeasure;};#endif//COMPONETNUTRITIONAL
Cpp
#include"componetnutritional.h"
#include <typeinfo>
ComponentNutritional::ComponentNutritional(QObject *parent):QObject(parent)
{
this->name = typeid(this).name();
this->dairyvalue = 0;
this->measure = "";
this->value = 0;
}
ComponentNutritional::~ComponentNutritional()
{
}
QString ComponentNutritional::getName()
{
return this->name;
}
float ComponentNutritional::getValue()
{
return this->value;
}
float ComponentNutritional::getDairyValue()
{
return this->dairyvalue;
}
QString ComponentNutritional::getMeasure()
{
return this->measure;
}
Inheriting class
Header
#ifndef VITAMIN_H
#define VITAMIN_H
#include <QObject>
#include "Library/Types/Base/componetnutritional.h"
class Vitamin : public ComponentNutritional
{
public:
explicit Vitamin(QObject *parent = 0);
~Vitamin();
Q_INVOKABLE Vitamin *setName(QString value);
Q_INVOKABLE Vitamin *setValue(float value);
Q_INVOKABLE Vitamin *setDairyValue(float value);
Q_INVOKABLE Vitamin *setMeasure(QString value);
};
class Vitamins: public QList<Vitamin>{
};
#endif // VITAMIN_H
Cpp
#include "vitamin.h"
Vitamin::Vitamin(QObject *parent): ComponentNutritional(parent)
{
}
Vitamin::~Vitamin()
{
}
Vitamin *Vitamin::setName(QString value)
{
this->name = value;
return this;
}
Vitamin *Vitamin::setValue(float value)
{
this->value = value;
return this;
}
Vitamin *Vitamin::setDairyValue(float value)
{
this->dairyvalue = value;
return this;
}
Vitamin *Vitamin::setMeasure(QString value)
{
this->measure = value;
return this;
}
Solution
#ifndef VITAMIN_H
#define VITAMIN_H
#include <QObject>
#include "Library/Types/Base/componetnutritional.h"
class Vitamin : public ComponentNutritional
{
public:
explicit Vitamin(QObject *parent = 0);
~Vitamin();
Q_INVOKABLE Vitamin *setName(QString value);
Q_INVOKABLE Vitamin *setValue(float value);
Q_INVOKABLE Vitamin *setDairyValue(float value);
Q_INVOKABLE Vitamin *setMeasure(QString value);
};
class Vitamins: public QList<Vitamin*>{ //Alterado para ponteiro
};
#endif // VITAMIN_H