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不允许通过"="操作符进行对象复制。

你可能感兴趣的:(QT编程)