Results 1 to 3 of 3

Thread: Invoking a QFileDialog from another dialog

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2009
    Location
    France
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Invoking a QFileDialog from another dialog

    Hi,

    I want to invoke a FileDialog from another dialog window :

    I am in my tool options configuration dialog box (which works in a classic manner, with Accept/Cancel buttons which respectively accept new configuration or cancel changes). In one of this, I need to make user select a directory, so I want to invoke QFileDialog for this.
    But system hangs at runtime, due to modal aspects.

    Any idea to launch QFileDialog from a dialog ?

    BR

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Invoking a QFileDialog from another dialog

    Hi there!

    I was curious if I could reproduce this problem:

    Qt Code:
    1. project file:
    2.  
    3. TEMPLATE = app
    4. TARGET = modalmodal
    5. SOURCES += main.cpp
    6. HEADERS += forms.h
    7.  
    8. forms.h
    9.  
    10. #ifndef FORMS_H
    11. #define FORMS_H
    12.  
    13. #include <QtGui>
    14. #include <QDebug>
    15.  
    16. class OptionDialog : public QDialog
    17. { Q_OBJECT
    18. public:
    19. OptionDialog() {
    20. setModal(true);
    21. setGeometry(100,100,320,240);
    22. setAttribute(Qt::WA_DeleteOnClose,true);
    23. button = new QPushButton("Open File ..",this);
    24. connect(button,SIGNAL(clicked()),this,SLOT(openFileDialog()));
    25. }
    26. protected slots:
    27. void openFileDialog() {
    28. QString fileName = QFileDialog::getOpenFileName(this, "Test Dialog", "", "Zip-File (*.zip)");
    29. qDebug() << fileName;
    30. }
    31. private:
    32. QPushButton* button;
    33. };
    34.  
    35. class MainForm : public QWidget
    36. { Q_OBJECT
    37. public:
    38. MainForm() {
    39. setGeometry(50,50,640,480);
    40. button = new QPushButton("Option Dialog",this);
    41. connect(button,SIGNAL(clicked()),this,SLOT(showOptionDlg()));
    42. }
    43. protected slots:
    44. void showOptionDlg() {
    45. OptionDialog* opt = new OptionDialog();
    46. opt->show();
    47. }
    48. private:
    49. QPushButton* button;
    50. };
    51.  
    52. #endif // FORMS_H
    53.  
    54. main.cpp:
    55.  
    56. #include <QtGui>
    57. #include <QApplication>
    58. #include "forms.h"
    59.  
    60. int main(int argc, char *argv[])
    61. {
    62. QApplication app(argc, argv);
    63.  
    64. MainForm mainform;
    65. mainform.show();
    66.  
    67. app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
    68. return app.exec();
    69. }
    To copy to clipboard, switch view to plain text mode 
    This works without any problems..

    Did you maybe miss to pass the modal option dialog as parent to the FileDialog?

    Johannes

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

    skimpax (24th March 2010)

  4. #3
    Join Date
    Jul 2009
    Location
    France
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Invoking a QFileDialog from another dialog

    OK, thanks to your example, I understood the error : It was related to modal as you suggested.
    Many thanks.

Similar Threads

  1. Invoking New Dialog
    By kb1lqc in forum Qt Programming
    Replies: 8
    Last Post: 5th November 2009, 15:23
  2. Replies: 7
    Last Post: 3rd July 2008, 08:02
  3. why QFileDialog does not display the default winxp dialog?
    By mismael85 in forum Qt Programming
    Replies: 5
    Last Post: 21st March 2008, 13:39
  4. Replies: 4
    Last Post: 13th June 2007, 15:37
  5. Invoking a browser...???
    By deepusrp in forum Newbie
    Replies: 4
    Last Post: 12th June 2007, 17:32

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.