Reputation: 61
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.
Upvotes: 4
Views: 2004
Reputation: 3255
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
The Q_OBJECT macro must appear in the private section of a class definition that declares its own signals and slots or that uses other services provided by Qt's meta-object system.
I'm guessing that you should move it before your public:
in mymodel.h
This was the SO post I used to find this:
What does the Q_OBJECT macro do? Why do all Qt objects need this macro?
Upvotes: 4