Results 1 to 7 of 7

Thread: Qt5/C++ - Signals and slots, QMainwindow to QDialog

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt5/C++ - Signals and slots, QMainwindow to QDialog

    That's the way, it works fine now, many thanks.
    If this dialog is being created and posted in a slot (say, in response to a button click or something), then the code you have written looks like it will result in a memory leak when the slot exits. If the dialog is meant to be transient (i.e. posted only for the duration of the slot's execution), then the more conventional way is to create the dialog on the stack instead of on the heap through new():

    Qt Code:
    1. void MainWindow::someSlot()
    2. {
    3. noobsForm myNoobs(driveDataList, file, ui->cboxDevice->currentText());
    4. QObject::connect( this, SIGNAL(progressUpdate(int)), &myNoobs, SLOT(updateProgress(int)));
    5. myNoobs.exec();
    6. }
    To copy to clipboard, switch view to plain text mode 

    In this way, the lifetime of the dialog is the same as the lifetime of the slot; when the slot exits, the "myNoobs" instance on the stack is automatically deleted.

    Alternatively, you could use your heap-based method, but add a call to
    Qt Code:
    1. myNoobs->setAttribute( Qt::WA_DeleteOnClose, true );
    To copy to clipboard, switch view to plain text mode 
    before calling exec(), which will cause Qt to delete the dialog instance when the dialog is closed.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. The following user says thank you to d_stranz for this useful post:

    jimbo (2nd October 2016)

Similar Threads

  1. Replies: 2
    Last Post: 30th November 2013, 00:19
  2. Replies: 2
    Last Post: 18th April 2013, 12:15
  3. Replies: 1
    Last Post: 26th March 2013, 02:04
  4. Replies: 0
    Last Post: 22nd September 2011, 10:31
  5. How to Call a QDialog in QMainWindow
    By mcht_z in forum Newbie
    Replies: 2
    Last Post: 13th April 2011, 06:43

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
  •  
Qt is a trademark of The Qt Company.