我创建了一个名为 video 的 Qt 类,如下所示:
视频.h
class Video : public QDjangoModel {
Q_OBJECT
// ...
public:
explicit Video(QObject *parent = 0);
// ...
};
视频.cpp
Video::Video(QObject *parent) : QDjangoModel(parent) {}
并发生以下错误:
In file included from ../OnlineVideoPlayer/video.h:7:0,
from ../OnlineVideoPlayer/video.cpp:28: ../../../bin/QtSDK/Desktop/Qt/4.8.1/gcc/include/QtCore/qobject.h: In
copy constructor 'QDjangoModel::QDjangoModel(const QDjangoModel&)':
../../../bin/QtSDK/Desktop/Qt/4.8.1/gcc/include/QtCore/qobject.h:333:5:
error: 'QObject::QObject(const QObject&)' is private
/usr/local/include/qdjango/db/QDjangoModel.h:72:22: error: within this
context In file included from ../OnlineVideoPlayer/video.cpp:28:0:
../OnlineVideoPlayer/video.h: In copy constructor 'Video::Video(const
Video&)': ../OnlineVideoPlayer/video.h:14:7: note: synthesized method
'QDjangoModel::QDjangoModel(const QDjangoModel&)' first required here
此类扩展名为的类QDjangoModel
(包含在QDjango中)并QDjangoModel
扩展QObject
。当我在 Qt creator 上创建类时,它会创建以下模板:
NewClass::NewClass(QObject *parent) : QObject(parent) {}
我认为: QObject(parent)
是父母的构造函数,所以我将其替换为: QDjangoModel(parent)
但似乎不正确。
问题:
Q1。什么: QObject(parent)
意思?
我搜索了初始化列表,我理解了以下代码的含义:
class NewClass {
public:
FileReader(QString name);
private:
QString m_name;
};
NewClass::NewClass(QString name) : m_name(name) {}
在这种情况下,
m_name = name;
在构造函数执行时执行,对吗?
但就我而言,
NewClass::NewClass(QObject *parent) : QObject(parent) {}
或者
NewClass::NewClass(QObject *parent) : QDjangoModel(parent) {}
不意味着
QObject = parent;
或者
QDjangoModel = parent;
显然,所以我对m_name(name)
案例的理解不适用于QObject(parent)
案例。
Q2。我该如何解决这个错误?