PDA

View Full Version : When drop a file from shared folder, the path could not be correctly obtained in QT



yw_hi
26th August 2012, 01:45
Hi,
I need to help to solve this problem that the path is not correctly obtained. I am running the QT in Window7 environment.

I shared a folder from another computer and opened the folder using window. The path of the file is
\\yw-desk3\users\yw\qttest\videodata\0000.bmp.
When I drap and drop the file to my qt applications, it only get
users\yw\qttest\videodata\0000.bmp
So the file cannot be opened since the path is not correct. How should I fix the problem? Here is the code that I used.

void MainWindow::dropEvent(QDropEvent *event)
{
const QMimeData *mimeData = event->mimeData();

if (!mimeData->hasUrls() || mimeData->urls().size() < 1)
return;


// In both cases, we need to remove the leading '/' that
// remains after 'file:///C:/' is truncated to '/C:/'

QString path = mimeData->urls().at(0).path().remove(0, 1);
openColorComponent(path);
}

Thanks

Frank

saa7_go
2nd November 2012, 10:07
you can use QUrl::toLocalFile() to get file path from a url.