PDA

View Full Version : Displaying file name (not the entire file name path)



Ferric
15th November 2011, 04:02
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()

{
QFileDialog::Options options;

QString selectedFilter;

fileName = QFileDialog::getOpenFileName(this,
tr("Select a Blaster File)"),
openFileNameLabel->text(),
tr("Blaster Files (*.cmd);;Text Files (*.txt)"),
&selectedFilter,
options);
if (!fileName.isEmpty())
openFileNameLabel->setText(fileName);


}

any help is appreciated. Thanks

Santosh Reddy
15th November 2011, 04:16
openFileNameLabel->setText(QFileInfo(fileName).fileName());
Documentation (http://doc.qt.nokia.com/4.7-snapshot/qfileinfo.html#fileName)

Ferric
15th November 2011, 04:23
Thanks Santosh, that worked well.