【发布时间】:2019-11-22 22:07:11
【问题描述】:
我知道这个问题已被问过很多次(例如there 和there),但不幸的是,这些解决方案不适用于我的情况。
背景
错误信息:'ADACEL::SPEECH::SRA::StatusRow::StatusRow(const ADACEL::SPEECH::SRA::StatusRow &)': attempting to reference a deleted function
根据我的阅读,我知道问题可能来自 QObject 的复制构造函数,但我不知道如何解决这个问题!
那么,看我的课:
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)
我的类的实例化:
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);
...
}
到目前为止我尝试了什么
我已经尝试过这个Q_DECLARE_METATYPE(ADACEL::SPEECH::SRA::StatusRow*),但是我遇到了错误Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system
另外,Q_DECLARE_METATYPE 仅在我使用指向 QVariant 的指针时才需要。以下是编译没有任何问题:
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));
【问题讨论】:
-
@eyllanesc Thx.a.lot!你的解决方案对我有用。另外,我认为我的问题是我使用了指针
QList<T*>*