Results 1 to 3 of 3

Thread: QFileDilaog:: cancel button

  1. #1
    Join Date
    Dec 2011
    Location
    Bangalore,India
    Posts
    38
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default QFileDilaog:: cancel button

    Hi all,

    I am able to open a fileDialog and get the file name (for example before selecting the filename, if I click the cancel button or close the fileDialog the messagebox is displayed which is in the code

    But the message box should be displayed after the open button is clicked, right now it is displayed if i click cancel button or close the fileDilaog. anyone can give some suggestions.
    I have attached the code

    Qt Code:
    1. if (!QFile::exists(f+func))
    2. {
    3. fileName = QFileDialog::getOpenFileName(this,tr("Open CSV File"), "", tr("CSV Files (*.csv)"));
    4.  
    5. QFile::copy(fileName, f+func);
    6.  
    7. QMessageBox::information(this,tr("Batgenerator"),tr("Import table succeed"));--------> MESSAGE box to be displayed after clicking open
    8. m_buttonimporttable->show();
    9.  
    10. if((m_listCSVmajCSV->selectedItems().count()==1))
    11. {
    12. m_buttonAddVarToFile->show();
    13. m_buttonMajCSV->show();
    14. m_checkBkMajCSV->show();
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    Thanks in Advance!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFileDilaog:: cancel button

    getOpenFileName() returns an empty string when cancel is clicked or the dialog is closed, so check fileName.isEmpty()

    Cheers,
    _

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

    kulsekarr (20th March 2015)

  4. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileDilaog:: cancel button

    Simply test if fileName is not empty
    Qt Code:
    1. if( !fileName.isEmpty() )
    2. {
    3. QFile::copy....
    4. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Adding a OK and Cancel button to QTableview
    By rex in forum Qt Programming
    Replies: 0
    Last Post: 24th July 2011, 17:32
  2. Replies: 4
    Last Post: 29th April 2011, 09:42
  3. Replies: 1
    Last Post: 17th February 2010, 23:17
  4. QDialog, editingFinished, and Cancel Button.
    By jeffpogo in forum Qt Programming
    Replies: 8
    Last Post: 3rd June 2009, 03:22
  5. How to show QProgressDialog without cancel button
    By rajesh in forum Qt Programming
    Replies: 1
    Last Post: 30th January 2007, 09:53

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.