Wednesday, October 24, 2012

type QWidget is not a direct base of MyWidget


Qt Code:

class MyWidget : public QMainWindow 
{ 
Q_OBJECT 
public: 
explicit MyWidget(QWidget *parent = 0); 

~MyWidget(); 
private: 
Ui::MyWidget *ui; 
}; 

MyWidget::MyWidget(QWidget *parent) 
: QWidget(parent)//ERROR 
{ 
QPushButton *quit = new QPushButton("Close Application", this); 

setGeometry(150,150,100,100); 
setFont(QFont("Times",12,QFont::Bold)); 

connect(quit,SIGNAL(clicked()),qApp,SLOT(quit())); 

Error: Type "QWidget" is not direct base of 'MyWidget'.
you will need to pass the parent to the QMainWindow constructor

MyWidget::MyWidget(QWidget *parent) 

: QMainWindow(parent) // no ERROR 


you will need to pass the parent to the QMainWindow constructor:

If this even does not fix the issue then you may have forgot to include the header file in .h file

# include 
 

No comments: