Reputation: 1039
I know this question has been asked numerous time (there and there for example) but unfortunately, those solutions are not working for my case.
Error message: 'ADACEL::SPEECH::SRA::StatusRow::StatusRow(const ADACEL::SPEECH::SRA::StatusRow &)': attempting to reference a deleted function
From my reading, I understand that the problem could be from the copy constructor of QObject, but I don't know how to fix this!
So, see my classe :
namespace ADACEL
{
namespace SPEECH
{
namespace SRA
{
class StatusRow: public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged)
public:
StatusRow(QObject *parent = 0);
StatusRow(const QString &name, const QString &color, QObject *parent = 0);
//StatusRow(const StatusRow&) = delete;
~StatusRow(void) {};
QString name() const;
void setName(const QString &name);
QString icon() const;
void setIcon(const QString &icon);
//StatusRow& operator=(const StatusRow&) = delete;
Q_SIGNALS:
void nameChanged();
void iconChanged();
private:
QString m_name;
QString m_icon;
};
}
}
}
Q_DECLARE_METATYPE(ADACEL::SPEECH::SRA::StatusRow)
Instantiation of my classe:
StatusWindow::StatusWindow(GUIDataLayer* pUiDataLayer) : QDeclarativeView(0),
m_statusRows(0)
{
setWindowModality(Qt::ApplicationModal);
m_statusRows = new QList<StatusRow*>();
m_statusRows->append(new StatusRow(TITLE_AUDIO_PROVIDER, ICON_OK));
m_statusRows->append(new StatusRow(TITLE_ADAPTER, ICON_ERROR));
rootContext()->setContextProperty("statusInfo", QVariant::fromValue(m_statusRows));
rootContext()->setContextProperty("uiDataLayer", pUiDataLayer);
...
}
I already tried this Q_DECLARE_METATYPE(ADACEL::SPEECH::SRA::StatusRow*)
but then I have the error Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system
Also, Q_DECLARE_METATYPE
is only necessary when I am using a pointer into the QVariant. The following is compiling without any problem :
QList<StatusRow*> statusRows;
statusRows.append(new StatusRow(TITLE_AUDIO_PROVIDER, ICON_OK));
statusRows.append(new StatusRow(TITLE_ASR_ENGINE, ICON_NONE));
statusRows.append(new StatusRow(TITLE_POST_PROCESSOR, ICON_NONE));
statusRows.append(new StatusRow(TITLE_ADAPTER, ICON_ERROR));
rootContext()->setContextProperty("statusInfo", QVariant::fromValue(statusRows));
Upvotes: 1
Views: 1342
Reputation: 244132
I do not observe the error you indicate, I also prefer to use QVariantList
instead of QList <T* >
to export a list of QObjects
:
main.cpp
using namespace ADACEL::SPEECH::SRA;
QVariantList statusRows;
statusRows.append(QVariant::fromValue(new StatusRow("TITLE_AUDIO_PROVIDER", "ICON_OK")));
statusRows.append(QVariant::fromValue(new StatusRow("TITLE_ASR_ENGINE", "ICON_NONE")));
statusRows.append(QVariant::fromValue(new StatusRow("TITLE_POST_PROCESSOR", "ICON_NONE")));
statusRows.append(QVariant::fromValue(new StatusRow("TITLE_ADAPTER", "ICON_ERROR")));
QQuickView view;
view.rootContext()->setContextProperty("statusInfo", QVariant::fromValue(statusRows));
Upvotes: 2