The code snippet you posted won't compile so it is not clear you have a running program. You should post code that compiles and use code tags. You need to think about what should happen and where: do you really want to create a new main window every time you click the button?
#include <QtCore>
#include <QtGui>
class SubWindowWidget
: public QLabel {public:
SubWindowWidget() {
setText("I'm a sub-window");
}
};
Q_OBJECT
public:
MainWindow() {
mdi = new QMdiArea(this);
l->addWidget(p);
l->addWidget(mdi);
w->setLayout(l);
setCentralWidget(w);
connect(p, SIGNAL(clicked()), this, SLOT(addSubWin()));
}
private:
QMdiArea *mdi;
private slots:
void addSubWin() {
SubWindowWidget *sw = new SubWindowWidget;
mdi->addSubWindow(sw);
sw->show();
}
};
int main(int argc, char **argv)
{
MainWindow mw;
mw.show();
app.exec();
}
#include "main.moc"
#include <QtCore>
#include <QtGui>
class SubWindowWidget: public QLabel {
public:
SubWindowWidget() {
setText("I'm a sub-window");
}
};
class MainWindow: public QMainWindow {
Q_OBJECT
public:
MainWindow() {
QWidget *w = new QWidget(this);
QPushButton *p = new QPushButton("New Sub-window", this);
mdi = new QMdiArea(this);
QVBoxLayout *l = new QVBoxLayout(w);
l->addWidget(p);
l->addWidget(mdi);
w->setLayout(l);
setCentralWidget(w);
connect(p, SIGNAL(clicked()), this, SLOT(addSubWin()));
}
private:
QMdiArea *mdi;
private slots:
void addSubWin() {
SubWindowWidget *sw = new SubWindowWidget;
mdi->addSubWindow(sw);
sw->show();
}
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MainWindow mw;
mw.show();
app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks