error: 'QObject& QObject::operator=(const QObject)' is private 问题解决

今天QT编程时遇到了这样的问题:

/opt/QtEmbedded-4.7.3/include/QtCore/qobject.h:309: error: ‘QObject& QObject::operator=(const QObject&)’ is private

/opt/QZXing/QZXing.h:28: error: within this context

弄了一会才明白是我构建对象时出了问题,我的构建过程如下:

QZXing decoder;
decoder = QZXing(QZXing::DecoderFormat_QR_CODE);

正确过程应该是:

QZXing *decoder;
decoder = new QZXing(QZXing::DecoderFormat_QR_CODE);

或者

QZXing decoder(QZXing::DecoderFormat_QR_CODE);

原因在于QZXing这个类是继承了QObject类的,而QObject不允许通过"="操作符进行对象复制。

#define FEATURE_POINT_NUM 7 struct DoNothingDeleter { template <typename T> void operator()(T*) const {} }; auto record2vm = [&](Record record) { ImplVm* implVm = new ImplVm(); implVm->setValue(DetnPointVmDF::GIndex, record.index); implVm->setValue(DetnPointVmDF::GPointID, record.subId == 0 ? QString::number(record.id) : QString("%1-%2").arg(record.id).arg(record.subId)); implVm->setValue(DetnPointVmDF::GPoint, QString("%1, %2, %3").arg(record.point.x()).arg(record.point.y()).arg(record.point.z())); implVm->setValue(DetnPointVmDF::GMt, record.mt); implVm->setValue(DetnPointVmDF::GAmplitude, record.amplitude > 0 ? QString::number(record.amplitude) : QString("--")); return implVm; }; AutoMtDetn::AutoMtDetn(QWidget* parent) : QWidget(parent) { init(); QObject::connect(m_close, &BtnBase::notifyRelease, this, &AutoMtDetn::handleClose); QObject::connect(m_mtDetermination, &BtnBase::notifyRelease, this, &AutoMtDetn::handleDetermination); QObject::connect(m_done, &BtnBase::notifyRelease, this, &AutoMtDetn::handleDone); QObject::connect(UiTransfer::stGetInstance(), &UiTransfer::notifyNaviStatue, this, &AutoMtDetn::handleNaviStatue, Qt::QueuedConnection); QObject::connect(UiTransfer::stGetInstance(), &UiTransfer::notifyTmsAmplitudeData, this, &AutoMtDetn::handleTmsAmplitude, Qt::QueuedConnection); QObject::connect(this, &AutoMtDetn::notifyAutoMtResult, this, &AutoMtDetn::handleAutoMtResult); QObject::connect(m_test150, &BtnBase::notifyRelease, this, [&]() { handleTmsAmplitude(150); }); QObject::connect(m_test100, &BtnBase::notifyRelease, this, [&]() { handleTmsAmplitude(100); }); QObject::connect(m_test80, &BtnBase::notifyRelease, this, [&]() { handleTmsAmplitude(80); }); QObject::connect(m_test60, &BtnBase::notifyRelease, this, [&]() { handleTmsAmplitude(60); }); QObject::connect(m_test20, &BtnBase::notifyRelease, this, [&]() { handleTmsAmplitude(20); }); //m_msgWdg = new InitialMtInputWdg(this); //m_msgWdg->show(); //
最新发布
04-03
``` class TestData : public QObject { Q_OBJECT public: TestData(QObject *parent = nullptr) : QObject(parent) {} //关键 必须这么写 TestData(const TestData &other) : QObject(other.parent()) { //this = other; // Copy other data members here this->Barcode = other.Barcode; this->CameraCounts = other.CameraCounts; this->GroupDefine = other.GroupDefine; this->Basic = other.Basic; this->Result = other.Result; this->Normal = other.Normal; this->Defocus = other.Defocus; this->m_bBarcode = other.m_bBarcode; this->m_bCameraCounts = other.m_bCameraCounts; this->m_bDefocus = other.m_bDefocus; this->m_bGroupDefine = other.m_bGroupDefine; } //Person &operator=(const Person &other) = delete; // 禁用赋值运算符 //关键 必须这么写 TestData &operator=(const TestData &other) { if (this != &other) { //this = other; // Copy other data members here this->Barcode = other.Barcode; this->CameraCounts = other.CameraCounts; this->GroupDefine = other.GroupDefine; this->Basic = other.Basic; this->Result = other.Result; this->Normal = other.Normal; this->Defocus = other.Defocus; this->m_bBarcode = other.m_bBarcode; this->m_bCameraCounts = other.m_bCameraCounts; this->m_bDefocus = other.m_bDefocus; this->m_bGroupDefine = other.m_bGroupDefine; } return *this; } public: QString Barcode; QString CameraCounts; QVector<QString> GroupDefine; BasicData Basic; ResultData Result; NormalData Normal; DefocusData Defocus; bool m_bBarcode; bool m_bCameraCounts; bool m_bGroupDefine; bool m_bDefocus; public: QVariantMap toVariantMap() const { QVariantMap map; if (m_bBarcode) { map["Barcode"] = QVariant::fromValue(Barcode); } if (m_bCameraCounts) { map["CameraCounts"] = QVariant::fromValue(CameraCounts); } if (m_bGroupDefine) { QVariantList list; for (auto item : GroupDefine) { list.append(item); } map["GroupDefine"] = list; } if (m_bDefocus) { QVariantMap tempDefocusMap = Defocus.toVariantMap(); if (tempDefocusMap.size() > 0) { map["Defocus"] = tempDefocusMap; } } QVariantMap tempBasicMap = Basic.toVariantMap(); if (tempBasicMap.size()>0) { map["Basic"] = tempBasicMap; } QVariantMap tempNormalMap = Normal.toVariantMap(); if (tempNormalMap.size() > 0) { map["Normal"] = tempNormalMap; } QVariantMap tempResultMap = Result.toVariantMap(); if (tempResultMap.size() > 0) { map["Result"] = tempResultMap; }```改用MFC+C++
03-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值