How to delete modeless dialog?
I want to create and show multiple dialog(or widget) on multiple user click.
so I written as:
Code:
void MainWindow::onIRSignalReport()
{
...
SignalWindow *pSignalWindow = new SignalWindow();
pSignalWindow->setSignalFile(fileName);
pSignalWindow->show();
}
onIRSignalReport() getting called on menu item clicks.
lets user clicked multiple times and multiple SignalWindow is displayed.
if user close one of the user window then how I delete that pointer(pSignalWindow ) ?:(
Re: How to delete modeless dialog?
set Qt::WA_DeleteOnClose for your window, e.g.
Code:
void MainWindow::onIRSignalReport()
{
...
SignalWindow *pSignalWindow = new SignalWindow();
pSignalWindow->setAttribute(Qt::WA_DeleteOnClose);
pSignalWindow->setSignalFile(fileName);
pSignalWindow->show();
}
Re: How to delete modeless dialog?
Thanks spirit.
and, how to close pSignalWindow if application closed?
if I pass this pointer also it is not getting closed.
SignalWindow *pSignalWindow = new SignalWindow((QDialog *)this);
Re: How to delete modeless dialog?
if you close your app, SignalWindow will not be closed, since you have not passed a parent into SignalWindow ctor, line 4 of your code. so, anyway you must to close this window.
Re: How to delete modeless dialog?
Code:
void MainWindow::onIRSignalReport()
{
...
SignalWindow *pSignalWindow
= new SignalWindow
((QDialog *)this);
pSignalWindow->setAttribute(Qt::WA_DeleteOnClose);
pSignalWindow->setSignalFile(fileName);
pSignalWindow->show();
}
now I am passing parent, right? but why It is not getting closed?
Re: How to delete modeless dialog?
I don't know, works fine for me. show us main.cpp code.
Re: How to delete modeless dialog?
Code:
int main(int argc, char *argv[])
{
GUIManager * pGUIManager = GUIManager::getInstance(); // GUIManager is a singleton
pGUIManager->initialize();
return a.exec();
}
bool GUIManager::initialize()
{
bool result = true; //TODO: may be required.
pMainWindow = new MainWindow;
return result;
}
Re: How to delete modeless dialog?
play with this test app
test.h
Code:
#ifndef TEST_H
#define TEST_H
#include <QDialog>
{
Q_OBJECT
public:
private slots:
void addWindowWithParent();
void addWindowWithoutParent();
};
#endif//TEST_H
test.cpp
Code:
#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();
}
main.cpp
Code:
#include <QApplication>
#include "test.h"
int main(int argc, char **argv)
{
Test test;
test.show();
return app.exec();
}
Re: How to delete modeless dialog?
Hi spirit,
your test app:
closing first window not closing 2nd window.
but, closing 2nd window closing all child window(3rd window onwords).
why it is so?
Re: How to delete modeless dialog?
if you create several windows with a parent and then close a parent window, then all windows will be closed too, but if you create several windows with parent and one (or several) windows without parent and then close a parent, then all windows wich have a parent will be close, but that windows which have not a parent will be stay opened.
Re: How to delete modeless dialog?
I have created several window with parent, but closing first parent not closing child window.
but closing 2nd window closing all child window.
I am using Qt4.3.1
Re: How to delete modeless dialog?
probably, at first you create a window witout parent and then you pressed "Add with parent" button and created a window and so on. so, when you closed first window it was closed, but when you closed second one, automatically all children have been closed too.
Re: How to delete modeless dialog?
fisrt one also created by passing parent, but how this matters.
if I am closing 1st window it should close all child window, no matters 1st window having parent or not. it is matters of 2nd window having parent.
Re: How to delete modeless dialog?
in main.cpp a new window is created, then when you click "Add without parent" and close first window the second will be opened. isn't it?
Re: How to delete modeless dialog?
I have never clicked on "Add without parent"
1 Attachment(s)
Re: How to delete modeless dialog?
take a look at video, works fine.