Ao compilar obtenho o seguinte erro, no QList. Estou utilizando o 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;
Classe Base
Header
#ifndef COMPONETNUTRITIONAL
#define COMPONETNUTRITIONAL
#include <QObject>
#include <QList>
class ComponentNutritional:public QObject
{
Q_OBJECT
public:
explicit ComponentNutritional(QObject *parent = 0);
~ComponentNutritional();
QString getName();
float getValue();
float getDairyValue();
QString getMeasure();
protected:
QString name;
float value;
float dairyvalue;
QString measure;
};
#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;
}
Classe que realiza a herança
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;
}
Solução
#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