Results 1 to 7 of 7

Thread: How to postpone a signal until present form is closed ?

  1. #1
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question How to postpone a signal until present form is closed ?

    Hi,

    I have a modal dialog started by a main window. When I press a certain button on this modal dialog, I want the dialog to close. After that, the main window should open a second modal dialog.

    I tried to first close() the first modal dialog in the event handler of the button in that dialog, and send a signal to the mainwindow.
    Qt Code:
    1. void CDekInfo::on_pbScan_clicked()
    2. {
    3. close();
    4. emit startSecondDialog( "123456789" );
    5. }
    To copy to clipboard, switch view to plain text mode 

    But of course the signal is handled immediately by the mainwindow and the second dialog is opened immediately, which is no good because the code after the exec() of my first modal dialog has to be executed before the second one is opened.

    Is there a way to 'post' a signal so that it will be executed only after my modal form has finished closing ? Sort of like when my main window enters its event loop again ?

    Regards,
    Marc

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to postpone a signal until present form is closed ?

    Why don't you simply examine the return value from the first dialog back in the mainwindow code, and use it to determine whether to launch the second dialog?

  3. #3
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to postpone a signal until present form is closed ?

    I don't get the connection between both dialogs... if you want to close the first after user pressed on a button: connect thi button with "close"-slot. When you want to open a second dialog - open it after exec() has returned.

    Qt Code:
    1. Dialog dlg;
    2. dlg.exec();
    3. Dialog dlg2;
    4. dlg2.exec();
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to postpone a signal until present form is closed ?

    Hi,

    @SixDegrees : thought of that too. But the dialog may be started in different places in my application. And then I would have to duplicated code.

    @FelixB : well, the situation is more complicated. The order in which dialogs are shown is not fixed. In fact, there are 3 or 4 dialogs and you may switch between the different dialogs at will.

    Guess I'll have to create a 'dialog starter' routine that checks return conditions when a dialog is closed. Too bad, I thought there would be a cleaner approach using signals and slots.

    Or maybe a single shot timer in my mainwindow and a flag that is set by a slot when a dialog has to be opened. Although maybe the timer may fire too soon, even before the dialog is closed, so I doubt that this is fool-proof.

    Further suggestions are appreciated,
    Best regards,
    Marc

  5. #5
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to postpone a signal until present form is closed ?

    what about QDialog::finished( int )-signal?

  6. #6
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to postpone a signal until present form is closed ?

    Hi FelixB,

    Tried that now. Unfortunately, it gives the same result. I send the signal to open the second dialog in the finished() slot of the first dialog. However, at that time the exec() function for the first dialog hasn't returned yet.

    I think I'll try some timer solution now. QDialog doesn't seem to have a signal that fires when my main dialog gets the focus. There is the focusInEvent, but I'm not sure if it occurs for the dialog itself, or for the widget in the dialog that gets the focus.

    Strange that there is no event or way to know that Qt has finished processing its signals. Maybe a signal could be sent when no more signals are pending

    Best regards,
    Marc

  7. #7
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default [solved] How to postpone a signal until present form is closed ?

    Hi,

    In case anybody cares : got it to work in a clean way now.

    I have a slot in my mainwindow. It has a parameter that says which dialog box to show. Any dialog can send a signal to this slot for showing another dialog.

    The mainwindow slot closes any dialog boxes that are still open, and remembers the dialog box to show. It then starts a timer (with QTimer::singleShot(0, this, SLOT(slot2)) to start a second slot.

    This second slot is executed after all windows are closed and any remaining signals are processed. It then finally shows the dialog box that was requested.

    Regards,
    Marc

Similar Threads

  1. Replies: 3
    Last Post: 23rd November 2009, 13:41
  2. Replies: 2
    Last Post: 12th February 2009, 22:23
  3. question about present a picture using QPixmap
    By lovelypp in forum Qt Programming
    Replies: 2
    Last Post: 12th July 2008, 15:43
  4. Connecting signal to form that is closing
    By steg90 in forum Qt Programming
    Replies: 3
    Last Post: 18th May 2007, 07:54
  5. modeless dialog closed signal?
    By gfunk in forum Qt Programming
    Replies: 2
    Last Post: 5th January 2007, 00:40

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.