今天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编程中遇到的对象复制错误,解释了为何直接使用赋值操作符会引发编译错误,并提供了正确的对象实例化方法。
1533

被折叠的 条评论
为什么被折叠?



