PDA

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



been_1990
3rd May 2009, 00: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?

spirit
3rd May 2009, 11: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);

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