Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qml FileDialog on Windows Runtime
Qt 6.11 is out! See what's new in the release blog

Qml FileDialog on Windows Runtime

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tank2005
    wrote on last edited by Tank2005
    #1

    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.

    p3c0P 1 Reply Last reply
    0
    • T Tank2005

      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.

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @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.

      157

      T 1 Reply Last reply
      0
      • p3c0P p3c0

        @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.

        T Offline
        T Offline
        Tank2005
        wrote on last edited by Tank2005
        #3

        @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);
        }
        
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved