Is the constructor closed?

C: / Qt /.../ mymodel.h: -1: In the member function 'void MainWindow :: createModel ()':

error: 'myModel :: myModel (QObject *)' is private

error: in 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.

+4
source share
1 answer

I will talk about this by saying that I just looked at SO for other Qt questions and then came across the documentation site below to come up with this assumption.

From http://doc.qt.digia.com/4.5/qobject.html#Q_OBJECT

The Q_OBJECT mask should appear in the private section of the class definition, which declares its own signals and slots or uses other services provided by the Qt meta-object system.

I assume you should port it before your public: in mymodel.h

This was the SO post I used for this:

What does the Q_OBJECT macro do? Why do all Qt objects need this macro?

+4
source

All Articles