haykart
haykart

Reputation: 957

Qt subclassing from QWidget

I write my own class which subclass from QWidget And this is my header file

#ifndef GRAPHMATRIX_H
#define GRAPHMATRIX_H

#include "treemodel.h"
#include <QWidget>
#include <Qt/qtableview.h>

class GraphMatrix : public QWidget
{
    Q_OBJECT
public:
    TreeModel& getModel();
    GraphMatrix(QWidget* parent = 0);
    void addTop(QString name);
    void cutComponent(GraphMatrix* component, QVector<int> columns);
private:
    TreeModel model;
    QTableView* view;
public slots:
    void changeValue(const QModelIndex& index);
};

#endif // GRAPHMATRIX_H

And I am getting this error

error C2248: 'QWidget::QWidget' : cannot access private member declared in class 'QWidget'

Can anyone help me?

Updated to add: I find answer, problem is in QList I must write QList. because QList is using copy constructor. Thank you for giving time for my problem

Upvotes: 0

Views: 3707

Answers (2)

haykart
haykart

Reputation: 957

The problem was in QList<GraphMatrix>, I must write QList<GraphMatrix*>, because QList is using a copy constructor.

Upvotes: 1

Roland Rabien
Roland Rabien

Reputation: 8836

It looks like you are trying to call the default constructor of QWidget which is private. Instead, your constructor needs to call the public constructor of QWidget as follows:

GraphMatrix::GraphMatrix(QWidget* parent) : QWidget(parent) {}

Upvotes: 2

Related Questions