Results 1 to 3 of 3

Thread: get filename from a QFileDialog

  1. #1
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default get filename from a QFileDialog

    Hi,

    This code gives me the full filename:
    Qt Code:
    1. QString usersfilename = QFileDialog::getOpenFileName(this,
    2. "Select source file",
    3. ".",
    4. "Text files (*.txt);; All files (*.*)");
    5.  
    6. ui->users_filename->setText(usersfilename);
    To copy to clipboard, switch view to plain text mode 

    Is there a function to get the filename without the full path?

    Thanks

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

    Default Re: get filename from a QFileDialog

    take a look at QFileInfo::fileName.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following 3 users say thank you to spirit for this useful post:

    Astronomy (17th November 2009), graciano (5th August 2009), sonulohani (11th June 2012)

  4. #3
    Join Date
    May 2009
    Location
    Vienna
    Posts
    91
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: get filename from a QFileDialog

    Quote Originally Posted by spirit View Post
    take a look at QFileInfo::fileName.
    Thanx!

    QFileinfo::basename().toStdString() was exact the one i needed too (-:

    greetz Astronomy

Similar Threads

  1. How to save file with QFileDialog
    By pnikolov in forum Qt Programming
    Replies: 11
    Last Post: 1st June 2012, 11:23
  2. Finding filename from QNetworkReply
    By Valheru in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2009, 10:29
  3. QFileDialog for choosing filename to save data
    By araglin in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2009, 09:46
  4. QFileDialog filename list order
    By joelthelion in forum Qt Programming
    Replies: 1
    Last Post: 28th January 2009, 15:58
  5. QFileDialog in Qt designer
    By tpf80 in forum Qt Tools
    Replies: 1
    Last Post: 17th May 2007, 01: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.