Results 1 to 5 of 5

Thread: question ? fileName[QString]

  1. #1
    Join Date
    Sep 2012
    Posts
    6
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default question ? fileName[QString]

    Hi All

    I am begginer in qt. I have just begun my adventure with qt.
    I need to display in comboBox fileName.
    I have QString filePath = "C:\\documnetnts\\filename.txt"
    I want to receive/extract only name or name with extension : filename.txt / filename

    I am trying something like this : (I found in docmunetation) : but It takes only the last 6 characters
    QString fileName = filePath.right(12);
    comboBox->addItem(fileName);

    Could anyone help me please ?


    I would appreciate for any help or advice

  2. #2
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: question ? fileName[QString]

    I am trying something like this : (I found in docmunetation) : but It takes only the last 6 characters
    QString fileName = filePath.right(12);
    you are wrong,
    filePath.right(12) will return filename.txt

    pls check with combobox width. may be your comboBox width is not enough.

    hope it helpz,
    bala

  3. #3
    Join Date
    Sep 2012
    Posts
    6
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: question ? fileName[QString]

    No, I have already found it :
    It is in class fileInfo

    example :
    QFileInfo fi("/tmp/archive.tar.gz");
    QString name = fi.fileName(); // name = "archive.tar.gz"

  4. #4
    Join Date
    Sep 2012
    Location
    Iran, Tehran
    Posts
    76
    Thanks
    17
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: question ? fileName[QString]

    To get the filename you can use QFileInfo class, it provides methods to do this.


    Added after 4 minutes:


    you have found it
    Last edited by Ashkan_s; 26th September 2012 at 13:16.

  5. #5
    Join Date
    Oct 2010
    Location
    Bangalore
    Posts
    52
    Thanks
    8
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: question ? fileName[QString]

    QStringList pList = filenamePath;
    pList.split(//);

    I hope this can work ....

Similar Threads

  1. Qstring question!!
    By maybnxtseasn in forum Qt Programming
    Replies: 1
    Last Post: 18th March 2012, 05:55
  2. Replies: 6
    Last Post: 7th January 2011, 08:31
  3. QString::toStdString in PyQt Question
    By di_zou in forum Newbie
    Replies: 1
    Last Post: 2nd November 2009, 20:09
  4. QString Question
    By fortyhideout12 in forum Qt Programming
    Replies: 1
    Last Post: 17th August 2009, 19:14
  5. Replies: 3
    Last Post: 28th March 2009, 15:37

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.