View Full Version : QDesktopServices::openUrl() not opening files in set path

3rd May 2009, 01:35
I created a app directory browser using QListView, to display my desktop items.
The following is my "file-opening" function:

void MainWindow::click2(const QModelIndex &var/*index*/)
QString o = var.data(0).toString();

qDebug() << o;
qDebug() << QDesktopServices::openUrl(o);

So with that and my index set as current directory, I can open any file.But if I change its index to any other directory thats not its current, it fails and qDebug says :
qDebug() << QDesktopServices::openUrl(o); --> --> false

I did some testing and passing this:

QUrl dir = directory+"\\"+var.data(0).toString();
qDebug() << QDesktopServices::openUrl(dir);

still gives me:
qDebug() << QDesktopServices::openUrl(dir); --> --> false

Any idea why?

3rd May 2009, 12:34
try to use this function QUrl::fromLocalFile.
so? you should modify you code like this

QUrl dir = QUrl::fromLocalFile(directory+"\\"+var.data(0).toString());
qDebug() << QDesktopServices::openUrl(dir);

4th May 2009, 19:34
It worked! Thanks. Can you explain why this worked and not the former?