Results 1 to 12 of 12

Thread: Open subwindow from parent window ctor

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Posts
    79
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    11
    Thanked 5 Times in 5 Posts

    Default Re: Open subwindow from parent window ctor

    Hmm, I think I didn't explain prcisely enough what I mean.

    After your first replies, my (working) code looks as follows:

    Qt Code:
    1. class EditCustomerImageDialog : public QDialog
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. EditCustomerImageDialog(Customer * c, QWidget * parent = 0, Qt::WindowFlags f = 0)
    7. : QDialog(parent, f)
    8. {
    9. //...
    10. openFile();
    11. }
    12. public slots:
    13. void openFile()
    14. {
    15. QString filename = QFileDialog::getOpenFileName(
    16. NULL, tr("Open face image"), "",
    17. tr("Image Files (*.jpg)"));
    18. //...
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 

    If I now open such a dialog from somewhere via
    Qt Code:
    1. EditCustomerImageDialog d (new Customer);
    2. d.exec();
    To copy to clipboard, switch view to plain text mode 

    what happens is that *first*, the openFileName Dialog pops up, nothing else.

    *After* having chosen a file, and after the openfilediag has disappeared, then the EditCustomerDialog pops up.

    Question:
    Can I realise that the EditCustomerDialog pops up, and directly after that, the open FIle diag should pop up ???

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

    Default Re: Open subwindow from parent window ctor

    did you try something like this?
    main.cpp
    Qt Code:
    1. ...
    2. int main(int argc, char **argv)
    3. {
    4. QApplication app(argc, argv);
    5. EditCustomerImageDialog ecid;
    6. ecid.show();
    7. const QString fileName(QFileDialog::getOpenFileName(
    8. NULL, tr("Open face image"), "",
    9. tr("Image Files (*.jpg)")));
    10. ecid.openFile(fileName);
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 
    EditCustomerImageDialog.cpp
    Qt Code:
    1. class EditCustomerImageDialog : public QDialog
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. EditCustomerImageDialog(Customer * c, QWidget * parent = 0, Qt::WindowFlags f = 0)
    7. : QDialog(parent, f)
    8. {
    9. //...
    10. //openFile();
    11. }
    12. public slots:
    13. void openFile(const QString &fileName = QString())
    14. {
    15. QString tmpFileName = fileName;
    16. if (tmpFileName.isEmpty())
    17. tmpFileName = QFileDialog::getOpenFileName(
    18. NULL, tr("Open face image"), "",
    19. tr("Image Files (*.jpg)"));
    20. //...
    21. }
    22. }
    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:

    olidem (13th May 2009)

  4. #3
    Join Date
    Feb 2009
    Posts
    79
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    11
    Thanked 5 Times in 5 Posts

    Default Re: Open subwindow from parent window ctor

    I know what you mean, but QDialog::show() returns immediately, while my ::exec() realisation blocks the caller. Ok, one can discuss for hours about this, it is a matter of taste, but I like the blocking thing more, also because this is just a modal dialog on top of my app, which is blocked while the dialog is shown.

    Thanks again for your support, great people out here!

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

    Default Re: Open subwindow from parent window ctor

    ok, another solution
    cpp
    Qt Code:
    1. Test::Test(QWidget *parent)
    2. : QDialog(parent)
    3. {
    4. ...
    5. QMetaObject::invokeMethod(this, "showDialog", Qt::QueuedConnection);
    6. ...
    7. }
    8.  
    9. void Test::showDialog()
    10. {
    11. QFileDialog::getOpenFileName(this);
    12. }
    To copy to clipboard, switch view to plain text mode 
    h
    Qt Code:
    1. private slots:
    2. void showDialog();
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    olidem (13th May 2009)

  7. #5
    Join Date
    Apr 2008
    Posts
    26
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanked 1 Time in 1 Post

    Default Re: Open subwindow from parent window ctor

    For this situation is usually use a single shot timer, put something like

    Qt Code:
    1. QTimer::singleShot(0, this, SLOT(openFile()));
    To copy to clipboard, switch view to plain text mode 

    at the end of your constructor for the main window. A time of zero will fire the slot after your window is visible.

    ps Hopefully the above code is correct i don't do much (any?) C++ put I think you'll get the idea.

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

    Default Re: Open subwindow from parent window ctor

    Quote Originally Posted by fifth View Post
    For this situation is usually use a single shot timer, put something like

    Qt Code:
    1. QTimer::singleShot(0, this, SLOT(openFile()));
    To copy to clipboard, switch view to plain text mode 

    at the end of your constructor for the main window. A time of zero will fire the slot after your window is visible.

    ps Hopefully the above code is correct i don't do much (any?) C++ put I think you'll get the idea.
    your code has the same behavior as my, because
    The default value for this property is 0. A QTimer with a timeout interval of 0 will time out as soon as all the events in the window system's event queue have been processed.
    but I don't use a timer.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  9. #7
    Join Date
    Apr 2008
    Posts
    26
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanked 1 Time in 1 Post

    Default Re: Open subwindow from parent window ctor

    Quote Originally Posted by spirit View Post
    but I don't use a timer.
    You win I didn't know about QMetaObject but will probably use your method now. It is more obvious in the code what is happening.

    For PyQt, just need to make sure you include the signature for the slot.

    Qt Code:
    1. class MainWindow(QWidget):
    2. def __init__(self, parent = None):
    3. super(MainWindow, self).__init__(parent)
    4.  
    5. QMetaObject.invokeMethod(self, "showDialog", Qt.QueuedConnection);
    6.  
    7. @pyqtSignature("showDialog()")
    8. def showDialog(self):
    9. QFileDialog.getOpenFileName(self)
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Best way to open a Qt window from web page?
    By montylee in forum Qt Programming
    Replies: 9
    Last Post: 19th January 2009, 08:04
  2. connecting child to parent window...
    By sumit in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2008, 21:28
  3. How to close parent window from child window?
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 14th October 2008, 11:40
  4. Getting a parent window from a QT/Linux library
    By nicolas44 in forum Qt Programming
    Replies: 8
    Last Post: 31st May 2007, 08:17
  5. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 08:41

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.