PDA

View Full Version : Cant use QWidget::setParent().



vitaR
1st July 2014, 04:26
Hi.

I have a new class called Piece, tried to inherit QLabel or QPushButton, everything is good, but once I try to set a parent (QWidget *container) its says

error: "void QWidget::setParent(QWidget*)' is inaccessible
void setParent(QWidget *parent);
^."

After see that QLabel wasn't working, tried with QPushButton and happened the same thing.

My Example Class:


#ifndef PIECE_H
#define PIECE_H
#include <QPushButton>
#include <QMouseEvent>

class Piece : QPushButton{
Q_OBJECT
public:
Piece();


};
#endif // PIECE_H

anda_skoa
1st July 2014, 08:24
Your code uses private inheritance, all the methods of the base class are then private.

You want public inheritance



class Piece : public QPushButton{


Cheers,
_

vitaR
2nd July 2014, 01:48
Thanks, it works.