PDA

View Full Version : It is Heritage again!!!



Stanfillirenfro
27th January 2013, 17:12
Hello!
I've got a lot of help days ago to solve a problem on the heritage. Another one has arose on the same topic and I am getting stucking deeply in it. I have a child window heriting from its parent. While displaying the child window, I just obtain EXACTELY the parent window all the time, I mean the main window. I can't therefore get to the child window.

My questions:
1- Why do I obtain the same and the parent window while trying to display the child window?
2- Could someone help me overcoming the problem?

Many thanks in advance!

He is my code:

Parent.h

#ifndef DEF_HERITAGE
#define DEF_HERITAGE

#include <QtGui>


class Heritage: public QMainWindow
{
Q_OBJECT

public:
Heritage(QWidget *parent = 0);
virtual ~Heritage();

public slots:
virtual void openChildWindow();

protected:
QStatusBar *m_barreEtat;
QMenu *m_menuFile, *m_aide;
QRadioButton *m_childButton;
QPushButton *m_quitButton;
QWidget *m_centralWidget;
QRadioButton *m_unBouton;
};

#endif // HERITAGE_H


Parent.cpp

#include "Heritage.h"
#include "ChildWindow.h"

Heritage::Heritage(QWidget *parent):QMainWindow(parent)
{
m_centralWidget = new QWidget(this);
m_centralWidget->setFixedSize(705, 390);

m_barreEtat = statusBar();

m_menuFile = menuBar()->addMenu("&File");
m_aide = menuBar()->addMenu("&Help");

m_childButton = new QRadioButton("Open childwindow", m_centralWidget);
m_childButton->move(50, 150);

m_quitButton = new QPushButton("Exit", m_centralWidget);
m_quitButton->move(200, 150);


connect(m_childButton, SIGNAL(clicked()), this, SLOT(openChildWindow()));
connect(m_quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));

setWindowTitle("Heritage");
setCentralWidget(m_centralWidget);


}

void Heritage::openChildWindow()
{
ChildWindow *childWindow = new ChildWindow(this);
childWindow->show();
}


Heritage::~Heritage()
{
;
}



Child.h

#ifndef DEF_CHILDWINDOW
#define DEF_CHILDWINDOW

#include<QtGui>

#include "Heritage.h"

class ChildWindow: public Heritage
{
Q_OBJECT

public:
ChildWindow(QWidget *parent = 0);
virtual ~ChildWindow();

public slots:


private:
QPushButton *m_childButton;

};

#endif // CHILDWINDOW_H

Child.cpp

#include "ChildWindow.h"

ChildWindow::ChildWindow(QWidget *parent):Heritage(parent)
{
this->setFixedSize(300, 150);
this->setWindowTitle("Child window");

m_childButton = new QPushButton("Exit", this);
m_childButton->move(50, 75);


connect(m_childButton, SIGNAL(clicked()), this, SLOT(close()));
}

ChildWindow::~ChildWindow()
{
;
}


main

#include <QApplication>
#include "Heritage.h"
#include <QtGui>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Heritage wind;

wind.show();

return app.exec();

}

Santosh Reddy
28th January 2013, 05:06
I have a child window heriting from its parent. While displaying the child window, I just obtain EXACTELY the parent window all the time, I mean the main window. I can't therefore get to the child window.
This is because ChildWindow is inherited from Heritage.

Don't inherit ChildWindow from Heritage, you will end up in such problems. Instead inherit it from QWidget or QMainWindow

Stanfillirenfro
28th January 2013, 08:25
Hello Reddy!
Many thanks for your help. It works!
Many thnaks again!