Qml FileDialog on Windows Runtime



  • I'm developing with Qt 5.5 for WinRT on Windows 10 64bit.

    Qml FileDialog can choose files from any directory. But those path can't use from C++ like this.

    void QTestView::open(const QString &fileUrl)
    {
    	QFile file(fileUrl);
    	file.open(QFile::ReadOnly); // fail
    }
    
    FileDialog {
    	id: fdlg
    	modality: Qt.WindowModal
    	title: "Choose a file"
    	selectExisting: true
    	selectMultiple: false
    	selectFolder: false
    	nameFilters: [ "Text files (*.txt)" ]
    	onAccepted: {
    		view.open(fileUrls[0]);
    	}
    }
    

    Please tell me how to read(or copy to the local directory) a file that selected from FileDialog on Windows Runtime.


  • Moderators

    @Tank2005 fileUrls returns url which is treated as QUrl on C++ side. So instead of QString use QUrl as an argument in your function. Then you can retrieve path as QString from QUrl.



  • @p3c0

    Thanks! It works well without files on OneDrive. I think that it's an other probrem because StorageFile::CopyAsync fails too.

    void copyFile(const QString &fileUrl)
    {
    	QFileInfo fromFile(QUrl(fileUrl).toLocalFile());
    	QString toPath = cd.absoluteFilePath(fromFile.fileName());
    	qDebug() << fromFile.absoluteFilePath() << "->" << toPath;
    	bool res = QFile::copy(fromFile.absoluteFilePath(), toPath);
    }

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.