error: use of deleted function 'QStringListModel& QStringListModel::operator=(const QStringListModel&)'
-
Hi all, I have been spending 3 weeks trying to get a basic app off the ground learning QT and have been pulling my hair out over this. I am trying to understand why I cannot set a Q_PROPERTY to a QStringListModel. Every time I setup the methods for this property I always receive this error from the compiler:
/home/drew/build-GEO-Desktop_Qt_6_2_0_GCC_64bit-Debug/GEO_autogen/EWIEGA46WW/moc_serial.cpp:120: error: use of deleted function 'QStringListModel& QStringListModel::operator=(const QStringListModel&)'
error: use of deleted function 'QStringListModel& QStringListModel::operator=(const QStringListModel&)'
120 | case 1: reinterpret_cast< QStringListModel>(_v) = _t->comModel(); break;
| ^public: explicit Serial(QObject *parent = nullptr); Q_PROPERTY(QStringListModel comModel READ comModel NOTIFY n_comModel) QStringListModel comModel(); signals: void comboBoxSerialPortsChanged(); void n_comModel();
#ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { auto *_t = static_cast<Serial *>(_o); (void)_t; void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QList<QSerialPortInfo>*>(_v) = _t->comboBoxSerialPorts(); break; case 1: *reinterpret_cast< QStringListModel*>(_v) = _t->comModel(); break; default: break; } } else if (_c == QMetaObject::WriteProperty) { } else if (_c == QMetaObject::ResetProperty) { } else if (_c == QMetaObject::BindableProperty) { }
What exactly does this mean? How can I go about resolving this? Is this the best way to provide QML variables to use?
-
Hi,
Because you can't copy QObject based classes. You should allocate your model on the heap and your property should return a pointer to a
QStringListModel
.