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. How to open files with QFileDialog or something?
Forum Updated to NodeBB v4.3 + New Features

How to open files with QFileDialog or something?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 421 Views
  • 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.
  • H Offline
    H Offline
    HMCL
    wrote on last edited by
    #1

    Screenshot from 2021-08-23 17-20-53.png
    Screenshot from 2021-08-23 17-21-13.png

    I want to open files which are located in "HMCL". When I clicked "Start" button, the folder is successfully open. However, I open the files, there is no response. How can I read or write the files in qml?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dannick Stark
      wrote on last edited by
      #2

      You can write a c++ function that will open the selected file and read its content.

      QString CompilerA::open(QString path)
      {
          QFile file(path);
      
          if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
              return;
          QTextStream out(&file);
          out.setCodec("UTF-8");
          QString result = out.readAll();
          result = result.toUtf8();
          file.close();
      
          return resut;
      }
      
      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bob64
        wrote on last edited by
        #3

        As far as I know there is no direct way to read file content from QML, so some sort of C++ extension is needed, as indicated by @Dannick-Stark.

        This StackOverflow answer describes an approach that exposes a "FileIO" object to QML from C++.

        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