Results 1 to 3 of 3

Thread: Displaying file name (not the entire file name path)

  1. #1
    Join Date
    Dec 2009
    Location
    New Zealand
    Posts
    54
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Displaying file name (not the entire file name path)

    Hi, I have the following working code but I only want to display the actual file name (not the entire file path) in the "openFileNameLabel" label. How can I do this?

    void Blaster::setOpenFileName()
    Qt Code:
    1. {
    2. QFileDialog::Options options;
    3.  
    4. QString selectedFilter;
    5.  
    6. fileName = QFileDialog::getOpenFileName(this,
    7. tr("Select a Blaster File)"),
    8. openFileNameLabel->text(),
    9. tr("Blaster Files (*.cmd);;Text Files (*.txt)"),
    10. &selectedFilter,
    11. options);
    12. if (!fileName.isEmpty())
    13. openFileNameLabel->setText(fileName);
    14.  
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 

    any help is appreciated. Thanks

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Displaying file name (not the entire file name path)

    Qt Code:
    1. openFileNameLabel->setText(QFileInfo(fileName).fileName());
    To copy to clipboard, switch view to plain text mode 
    Documentation

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

    Ferric (15th November 2011)

  4. #3
    Join Date
    Dec 2009
    Location
    New Zealand
    Posts
    54
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Displaying file name (not the entire file name path)

    Thanks Santosh, that worked well.

Similar Threads

  1. QCryptographicHash an entire file
    By pyramation in forum Qt Programming
    Replies: 2
    Last Post: 4th November 2010, 00:41
  2. Specify file path for RCC
    By becrux in forum Qt Tools
    Replies: 0
    Last Post: 15th September 2010, 12:41
  3. QHttp.get() is failing to download the entire file
    By WinchellChung in forum Newbie
    Replies: 0
    Last Post: 19th February 2010, 21:58
  4. remember file path
    By eric in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2008, 17:52
  5. Accessing the entire file..
    By Kapil in forum Newbie
    Replies: 1
    Last Post: 28th April 2006, 08:41

Tags for this Thread

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.