PDA

View Full Version : question ? fileName[QString]



wiatrak11
26th September 2012, 12:16
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 ;)

BalaQT
26th September 2012, 12:58
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

wiatrak11
26th September 2012, 13:10
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"

Ashkan_s
26th September 2012, 13:16
To get the filename you can use QFileInfo class, it provides methods to do this.

Added after 4 minutes:

you have found it ;)

pradeepreddyg95
26th September 2012, 18:28
QStringList pList = filenamePath;
pList.split(//);

I hope this can work ....