Results 1 to 9 of 9

Thread: Processo Ok or Cancel in a QFileDialog

  1. #1
    Join Date
    Jan 2009
    Posts
    78
    Thanks
    21
    Thanked 1 Time in 1 Post

    Default Processo Ok or Cancel in a QFileDialog

    Hi

    I'm using this function to get a file name.
    Qt Code:
    1. void class::function(){
    2. QFileDialog::Options options;
    3. QString selectedFilter;
    4. QString fileName = QFileDialog::getOpenFileName(this,
    5. tr("QFileDialog::getOpenFileName()"),
    6. lineEdit->text(),
    7. tr("PNG image format (*.png)"),
    8. &selectedFilter,
    9. options);
    10. if (!fileName.isEmpty())
    11. lineEdit->setText(fileName);
    12. }
    To copy to clipboard, switch view to plain text mode 

    How can i know if the user pressed Ok or Cancel?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Posts
    132
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Processo Ok or Cancel in a QFileDialog

    Basically user can only press OK when a filename is selected.

    So filename not empty -> user pressed ok.

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

    gt.beta2 (20th February 2009)

  4. #3
    Join Date
    Jan 2009
    Posts
    78
    Thanks
    21
    Thanked 1 Time in 1 Post

    Default Re: Processo Ok or Cancel in a QFileDialog

    But imagine it wad a Dialog made by me ... how to teste if the ok was the button presed?

  5. #4
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Processo Ok or Cancel in a QFileDialog

    Use the QDialog::accept() and QDialog::reject() slots by connecting your buttons to these slots. Then you can find out what the user clicked by calling QDialog::result().

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

    gt.beta2 (20th February 2009)

  7. #5
    Join Date
    Jan 2009
    Posts
    78
    Thanks
    21
    Thanked 1 Time in 1 Post

    Default Re: Processo Ok or Cancel in a QFileDialog

    So the same thing is valid for the initial question about the QFileDialog?
    Instead of testing if the field is empty i can test the accept or reject like said above?

  8. #6
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Processo Ok or Cancel in a QFileDialog

    Yes, but then you must use a file dialog instance. It won't work when using the file dialog's static methods.

  9. The following user says thank you to rexi for this useful post:

    gt.beta2 (20th February 2009)

  10. #7
    Join Date
    Jan 2009
    Posts
    78
    Thanks
    21
    Thanked 1 Time in 1 Post

    Default Re: Processo Ok or Cancel in a QFileDialog

    OK ... now i managed to know if the dialog was terminated with OK or Cancel.

    And let me make the last newbie question for today

    Imagine a dialog with :
    1. lineEdit
    2. cancelButton
    3. pushButton


    I call this dialog from the main application and the i want to use the contents of lineEdit there. Let's sai ... make a copy to lineEdit_2.

    How is this managed?

    Thanks

  11. #8
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Processo Ok or Cancel in a QFileDialog

    Simply add a method to your dialog that returns the contents of the lineedit. Whenever you need the value, call that method. It's the same principle as with QFileDialog: when you need to know what files were selected, you call QFileDialog::selectedFiles()

  12. The following user says thank you to rexi for this useful post:

    gt.beta2 (20th February 2009)

  13. #9
    Join Date
    Jan 2009
    Posts
    78
    Thanks
    21
    Thanked 1 Time in 1 Post

    Default Re: Processo Ok or Cancel in a QFileDialog


    ofcourse

Similar Threads

  1. QFileDialog in Qt designer
    By tpf80 in forum Qt Tools
    Replies: 1
    Last Post: 17th May 2007, 00: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.