play with this test app
test.h
#ifndef TEST_H
#define TEST_H
#include <QDialog>
{
Q_OBJECT
public:
private slots:
void addWindowWithParent();
void addWindowWithoutParent();
};
#endif//TEST_H
#ifndef TEST_H
#define TEST_H
#include <QDialog>
class Test: public QDialog
{
Q_OBJECT
public:
Test(QWidget *parent = 0);
private slots:
void addWindowWithParent();
void addWindowWithoutParent();
};
#endif//TEST_H
To copy to clipboard, switch view to plain text mode
test.cpp
#include <QtGui>
#include "test.h"
{
hbl->addWidget(pb1);
hbl->addWidget(pb2);
connect(pb1, SIGNAL(clicked()), SLOT(addWindowWithParent()));
connect(pb2, SIGNAL(clicked()), SLOT(addWindowWithoutParent()));
setWindowTitle(tr("main"));
}
void Test::addWindowWithParent()
{
Test *test = new Test(this);
test->setAttribute(Qt::WA_DeleteOnClose);
test->move(x() + 40, y() + 40);
test->setWindowTitle(tr("with parent"));
test->show();
}
void Test::addWindowWithoutParent()
{
Test *test = new Test();
test->setAttribute(Qt::WA_DeleteOnClose);
test->move(x() + 40, y() + 40);
test->setWindowTitle(tr("without parent"));
test->show();
}
#include <QtGui>
#include "test.h"
Test::Test(QWidget *parent)
: QDialog(parent)
{
QHBoxLayout *hbl = new QHBoxLayout(this);
QPushButton *pb1 = new QPushButton(tr("Add window with parent"));
QPushButton *pb2 = new QPushButton(tr("Add window without parent"));
hbl->addWidget(pb1);
hbl->addWidget(pb2);
connect(pb1, SIGNAL(clicked()), SLOT(addWindowWithParent()));
connect(pb2, SIGNAL(clicked()), SLOT(addWindowWithoutParent()));
setWindowTitle(tr("main"));
}
void Test::addWindowWithParent()
{
Test *test = new Test(this);
test->setAttribute(Qt::WA_DeleteOnClose);
test->move(x() + 40, y() + 40);
test->setWindowTitle(tr("with parent"));
test->show();
}
void Test::addWindowWithoutParent()
{
Test *test = new Test();
test->setAttribute(Qt::WA_DeleteOnClose);
test->move(x() + 40, y() + 40);
test->setWindowTitle(tr("without parent"));
test->show();
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QApplication>
#include "test.h"
int main(int argc, char **argv)
{
Test test;
test.show();
return app.exec();
}
#include <QApplication>
#include "test.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
Test test;
test.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks