Unsolved How to get return path from a customized QFileDialog widget
-
I have created a custom QFileDialog widget with the following properties. Now, I wanted when it is executing and a file selected, I can get the path. How should I do that?
QList<QUrl> sharedDriveBasedSMB;
sharedDriveBasedSMB << QUrl::fromLocalFile(QDir("//DC1/C$/Users/").absolutePath());QFileDialog o_dialogSource; o_dialogSource.setOption(QFileDialog::DontUseNativeDialog); o_dialogSource.setSidebarUrls(sharedDriveBasedSMB); o_dialogSource.getOpenFileName(this, "Choose File"); o_dialogSource.exec();
QFileDialog will executed but I wanted to get the file path too. I don't know how should I do that. I wanted a result like the following:
QString path = QFileDialog(...);
But I don't know in a customized QFileDialog how should I introduced path variable to it.
-
-
@Christian-Ehrlicher I have used the following code, but when QMessageBox executed it shows just an empty string to me. Where is the problem?
QString fileName; QFileDialog dialog; dialog.setOption(QFileDialog::DontUseNativeDialog); QList<QUrl> drives; drives << QUrl::fromLocalFile(QDir("//DC1/C$/Users/").absolutePath()); dialog.setSidebarUrls(drives); dialog.selectUrl(fileName); dialog.exec(); QMessageBox::information(this, "Message", fileName);
-
Hi,
You are calling the wrong function. It's selectedUrls as @Christian-Ehrlicher linked.
-
@Azadshahr
And additionally you need to get theselectedUrls()
after executing the dialog, not before!