I have created teh childwindow with ChildWindow.h and ChildWindow.cpp. Isn't it the way to create a window?
Can you show where is this ?. Post specific line of code where this is beig done.
According to my knowledge, by clicking on this button, a signal should be emitted to the main window to display the childwindow.
When clicked a signal will be emitted and Haritage:penChildWindow() slot will be executed. In this slot there is no code to create/show ChildWindoe. All this slot does is to show the m_childWindow (QPushButton). m_childWindow is QPushButton (NOT ChildWindow).
I some how feel you are confused between QPushButton & ChildWidget, or the posted is not what you wanted to post.
No, a button is a widget on wich a click can be done. A childwidget can be a window with buttons.
This seems ok. Then what is that makes you think a ChildWindow is created?
Try answering these...
1. Point me to the code where ChildWindow is created?
2. Point me to the code where ChildWindow is showed?
3. Why are you creating a QWidget in ChildWindow ctor?
4. Why are you connecting a QPushButton::clicked() signel to QPushButton::show()?
5. Why are you setting QMainWindow (m_centralZone) as central widget of Heritage?
I hope by the time you answer these questions, you should understand that these are the things you did worng in the code.
If it is still not clear, please refresh your C++ basics.
Added after 24 minutes:
Ok here is modified to work code
main.cpp
#include <QApplication>
#include "Heritage.h"
#include <QtGui>
int main(int argc, char *argv[])
{
Heritage wind;
wind.show();
return app.exec();
}
#include <QApplication>
#include "Heritage.h"
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Heritage wind;
wind.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Heritage.h
#ifndef DEF_HERITAGE
#define DEF_HERITAGE
#include <QtGui>
class ChildWindow;
{
Q_OBJECT
public:
explicit Heritage
(QWidget *parent
= 0);
virtual ~Heritage();
public slots:
void openChildWindow();
protected:
ChildWindow *m_childWindow;
};
#endif // HERITAGE_H
#ifndef DEF_HERITAGE
#define DEF_HERITAGE
#include <QtGui>
class ChildWindow;
class Heritage: public QMainWindow
{
Q_OBJECT
public:
explicit Heritage(QWidget *parent = 0);
virtual ~Heritage();
public slots:
void openChildWindow();
protected:
ChildWindow *m_childWindow;
QPushButton *m_childButton;
QPushButton *m_quitButton;
};
#endif // HERITAGE_H
To copy to clipboard, switch view to plain text mode
Heritage.cpp
#include "Heritage.h"
#include "ChildWindow.h"
Heritage
::Heritage(QWidget *parent
) , m_childWindow(new ChildWindow(0))
{
m_childWindow->setWindowTitle("ChildWindow");
m_childWindow->hide();
centralWidget->setFixedSize(400, 200);
m_childButton
= new QPushButton("Open childwindow", centralWidget
);
m_childButton->move(50, 150);
m_quitButton->move(200, 150);
connect(m_childButton, SIGNAL(clicked()), this, SLOT(openChildWindow()));
connect(m_quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
setWindowTitle("Heritage");
setCentralWidget(centralWidget);
}
void Heritage::openChildWindow()
{
m_childWindow->show();
}
Heritage::~Heritage()
{
;
}
#include "Heritage.h"
#include "ChildWindow.h"
Heritage::Heritage(QWidget *parent)
: QMainWindow(parent)
, m_childWindow(new ChildWindow(0))
{
m_childWindow->setWindowTitle("ChildWindow");
m_childWindow->hide();
QWidget *centralWidget = new QWidget(this);
centralWidget->setFixedSize(400, 200);
m_childButton = new QPushButton("Open childwindow", centralWidget);
m_childButton->move(50, 150);
m_quitButton = new QPushButton("Exit", 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(centralWidget);
}
void Heritage::openChildWindow()
{
m_childWindow->show();
}
Heritage::~Heritage()
{
;
}
To copy to clipboard, switch view to plain text mode
ChildWindow.h
#ifndef DEF_CHILDWINDOW
#define DEF_CHILDWINDOW
#include<QtGui>
{
Q_OBJECT
public:
explicit ChildWindow
(QWidget *parent
= 0);
virtual ~ChildWindow();
private:
};
#endif // CHILDWINDOW_H
#ifndef DEF_CHILDWINDOW
#define DEF_CHILDWINDOW
#include<QtGui>
class ChildWindow: public QWidget
{
Q_OBJECT
public:
explicit ChildWindow(QWidget *parent = 0);
virtual ~ChildWindow();
private:
QPushButton *m_childButton;
};
#endif // CHILDWINDOW_H
To copy to clipboard, switch view to plain text mode
ChildWindow.cpp
#include "ChildWindow.h"
ChildWindow
::ChildWindow(QWidget *parent
){
m_childButton
= new QPushButton("ChildWindow Button",
this);
m_childButton->setFixedSize(350, 150);
}
ChildWindow::~ChildWindow()
{
;
}
#include "ChildWindow.h"
ChildWindow::ChildWindow(QWidget *parent)
: QWidget(parent)
{
m_childButton = new QPushButton("ChildWindow Button", this);
m_childButton->setFixedSize(350, 150);
}
ChildWindow::~ChildWindow()
{
;
}
To copy to clipboard, switch view to plain text mode
Bookmarks