Results 1 to 4 of 4

Thread: QDialog modeless problem

  1. #1
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    2

    Default QDialog modeless problem

    Hi, i'm new at QT Developing. I read the C++ GUI Programming with C++ but i wasn't able to find the answer to my question.

    I want to open my custom QDialog, it's a modeless and i'm not intrested in waiting its execution so i decided to open it with the show() method. This how i open it :

    Qt Code:
    1. {
    2. if (!dialog) {
    3. dialog = new MyCustonDialog(this);
    4. }
    5. dialog->show();
    6. dialog->raise();
    7. dialog->activateWindow();
    8. }
    To copy to clipboard, switch view to plain text mode 

    I have alse setted Qt::WA_DeleteOnClose on the dialog, so it must be destroyed when closed.

    The problem is. The first time the dialog is opened it shows up correctly, but the second time, even if the destructor is called the dialog pointer is not NULL and the constructor is not called again causing a Segmentation Fault on the show() method.

    How can i solve it?

    If you're instrested in, i'm using Mac OS X Leopard with QT 4.5, and GCC 4.2.

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QDialog modeless problem

    either just do not delete it but just let it become hidden (no problem at all; it will just use a bit of memory...)

    or

    store the pointer to the dialog in a QPointer (always a good idea!) so you get "notified" (well, not you, but the QPointer) about the demise of the dialog and you do not end up with an invalid dangling pointer.

    HTH

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

    sgtbash (1st May 2009)

  4. #3
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QDialog modeless problem

    delete only deletes object from memory and destructor is supposed to make some "cleaning", but none of them knows anything about pointers to that object, so there is no way to set the pointer to 0. You have to do it by yourself, or as it was said use QPointer instead of normal pointer, which is smarter and can set itself to 0 when the pointing object is deleted.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  5. The following user says thank you to faldzip for this useful post:

    sgtbash (1st May 2009)

  6. #4
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    2

    Default Re: QDialog modeless problem

    Thank you guys for your help!

    The strangest thing was that for some object the pointer became null, and for other not. I googled a lot but i wasn't able to understand what was happening. Using a QPointer everything works perfectly!

Similar Threads

  1. problem with show/exec of Qdialog
    By dudedude in forum Qt Programming
    Replies: 1
    Last Post: 23rd December 2008, 11:20
  2. Problem with QDialog class
    By sudheer168 in forum Qt Programming
    Replies: 4
    Last Post: 23rd December 2008, 09:03
  3. QDialog derived and focus problem
    By elm66 in forum Qt Programming
    Replies: 1
    Last Post: 4th April 2008, 21:52
  4. connect problem QDialog
    By Zergi in forum Newbie
    Replies: 1
    Last Post: 1st January 2008, 13:36
  5. QDialog / QListView problem
    By harakiri in forum Qt Programming
    Replies: 1
    Last Post: 10th July 2007, 18:31

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.