构造函数是私有的?
C:/Qt/.../mymodel.h:-1: 在成员函数 'void MainWindow::createModel()':
error: 'myModel::myModel(QObject*)' is private
error: 在此上下文中
mymodel.h:
#ifndef MYMODEL_H
#define MYMODEL_H
#include <QStandardItemModel>
class myModel : public QStandardItemModel
{
public:
Q_OBJECT
myModel(QObject *parent = 0);
};
#endif // MYMODEL_H
mymodel.cpp:
#include "mymodel.h"
myModel::myModel(QObject *parent) :
QStandardItemModel(parent)
{
}
mainwindow.h
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow();
private slots:
...
signals:
...
private:
...
myModel *model;
};
mainwindow.cpp:
void MainWindow::createModel()
{
model = new myModel(this);
谢谢。
C:/Qt/.../mymodel.h:-1:
In member function 'void MainWindow::createModel()':
error: 'myModel::myModel(QObject*)' is private
error: within this context
mymodel.h:
#ifndef MYMODEL_H
#define MYMODEL_H
#include <QStandardItemModel>
class myModel : public QStandardItemModel
{
public:
Q_OBJECT
myModel(QObject *parent = 0);
};
#endif // MYMODEL_H
mymodel.cpp:
#include "mymodel.h"
myModel::myModel(QObject *parent) :
QStandardItemModel(parent)
{
}
mainwindow.h
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow();
private slots:
...
signals:
...
private:
...
myModel *model;
};
mainwindow.cpp:
void MainWindow::createModel()
{
model = new myModel(this);
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将在开头说,我刚刚浏览了其他 Qt 问题,然后偶然发现了下面的文档站点,得出了这个猜测。
来自 http://doc.qt.digia.com/4.5/qobject.html #Q_OBJECT
我猜你应该把它移到 mymodel.h 中的
public:
之前这是我用来找到这个的 SO 帖子:
Q_OBJECT 宏有什么作用?为什么所有 Qt 对象都需要这个宏?
I'm going to preface this with saying that I just browsed SO for other Qt questions and then stumbled around the documentation site below to arrive at this guess.
From http://doc.qt.digia.com/4.5/qobject.html#Q_OBJECT
I'm guessing that you should move it before your
public:
in mymodel.hThis was the SO post I used to find this:
What does the Q_OBJECT macro do? Why do all Qt objects need this macro?