Results 1 to 16 of 16

Thread: How to delete modeless dialog?

  1. #1
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Question How to delete modeless dialog?

    I want to create and show multiple dialog(or widget) on multiple user click.
    so I written as:

    Qt Code:
    1. void MainWindow::onIRSignalReport()
    2. {
    3. ...
    4. SignalWindow *pSignalWindow = new SignalWindow();
    5. pSignalWindow->setSignalFile(fileName);
    6. pSignalWindow->show();
    7. }
    To copy to clipboard, switch view to plain text mode 

    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 ) ?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to delete modeless dialog?

    set Qt::WA_DeleteOnClose for your window, e.g.
    Qt Code:
    1. void MainWindow::onIRSignalReport()
    2. {
    3. ...
    4. SignalWindow *pSignalWindow = new SignalWindow();
    5. pSignalWindow->setAttribute(Qt::WA_DeleteOnClose);
    6. pSignalWindow->setSignalFile(fileName);
    7. pSignalWindow->show();
    8. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following user says thank you to spirit for this useful post:

    rajesh (16th June 2009)

  4. #3
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default 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);

  5. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default 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.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. #5
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to delete modeless dialog?

    Qt Code:
    1. void MainWindow::onIRSignalReport()
    2. {
    3. ...
    4. SignalWindow *pSignalWindow = new SignalWindow((QDialog *)this);
    5. pSignalWindow->setAttribute(Qt::WA_DeleteOnClose);
    6. pSignalWindow->setSignalFile(fileName);
    7. pSignalWindow->show();
    8. }
    To copy to clipboard, switch view to plain text mode 

    now I am passing parent, right? but why It is not getting closed?

  7. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to delete modeless dialog?

    I don't know, works fine for me. show us main.cpp code.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  8. #7
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to delete modeless dialog?

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4.  
    5. GUIManager * pGUIManager = GUIManager::getInstance(); // GUIManager is a singleton
    6. pGUIManager->initialize();
    7.  
    8. return a.exec();
    9. }
    10.  
    11. bool GUIManager::initialize()
    12. {
    13. bool result = true; //TODO: may be required.
    14.  
    15. pMainWindow = new MainWindow;
    16.  
    17. return result;
    18. }
    To copy to clipboard, switch view to plain text mode 

  9. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to delete modeless dialog?

    play with this test app
    test.h
    Qt Code:
    1. #ifndef TEST_H
    2. #define TEST_H
    3.  
    4. #include <QDialog>
    5.  
    6. class Test: public QDialog
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. Test(QWidget *parent = 0);
    12.  
    13. private slots:
    14. void addWindowWithParent();
    15. void addWindowWithoutParent();
    16.  
    17. };
    18.  
    19. #endif//TEST_H
    To copy to clipboard, switch view to plain text mode 

    test.cpp
    Qt Code:
    1. #include <QtGui>
    2. #include "test.h"
    3.  
    4. Test::Test(QWidget *parent)
    5. : QDialog(parent)
    6. {
    7. QHBoxLayout *hbl = new QHBoxLayout(this);
    8. QPushButton *pb1 = new QPushButton(tr("Add window with parent"));
    9. QPushButton *pb2 = new QPushButton(tr("Add window without parent"));
    10.  
    11. hbl->addWidget(pb1);
    12. hbl->addWidget(pb2);
    13.  
    14. connect(pb1, SIGNAL(clicked()), SLOT(addWindowWithParent()));
    15. connect(pb2, SIGNAL(clicked()), SLOT(addWindowWithoutParent()));
    16.  
    17. setWindowTitle(tr("main"));
    18. }
    19.  
    20. void Test::addWindowWithParent()
    21. {
    22. Test *test = new Test(this);
    23. test->setAttribute(Qt::WA_DeleteOnClose);
    24. test->move(x() + 40, y() + 40);
    25. test->setWindowTitle(tr("with parent"));
    26. test->show();
    27. }
    28.  
    29. void Test::addWindowWithoutParent()
    30. {
    31. Test *test = new Test();
    32. test->setAttribute(Qt::WA_DeleteOnClose);
    33. test->move(x() + 40, y() + 40);
    34. test->setWindowTitle(tr("without parent"));
    35. test->show();
    36. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "test.h"
    3.  
    4. int main(int argc, char **argv)
    5. {
    6. QApplication app(argc, argv);
    7.  
    8. Test test;
    9. test.show();
    10.  
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  10. #9
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default 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?

  11. #10
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default 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.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  12. #11
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default 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

  13. #12
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default 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.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  14. #13
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default 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.

  15. #14
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default 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?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  16. #15
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to delete modeless dialog?

    I have never clicked on "Add without parent"

  17. #16
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to delete modeless dialog?

    take a look at video, works fine.
    Attached Files Attached Files
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. Replies: 17
    Last Post: 2nd June 2009, 10:18
  2. Modeless dialog disappearing
    By Raccoon29 in forum Qt Programming
    Replies: 4
    Last Post: 15th September 2007, 11:38
  3. Delete dialog
    By Krish_ng in forum Qt Programming
    Replies: 3
    Last Post: 9th August 2007, 12:42
  4. modeless dialog closed signal?
    By gfunk in forum Qt Programming
    Replies: 2
    Last Post: 5th January 2007, 00:40
  5. modeless dialog
    By mhoover in forum Newbie
    Replies: 2
    Last Post: 23rd March 2006, 22:56

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.