Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Asynchronous file IO
Qt 6.11 is out! See what's new in the release blog

Asynchronous file IO

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 7.0k 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.
  • H Offline
    H Offline
    Hesam_GL
    wrote on last edited by
    #1

    Are there any facilities for asynchronous file IO in Qt?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kuzulis
      Qt Champions 2020
      wrote on last edited by
      #2

      Hi. It seems isn't present.

      Async I/O is used only for Sockets, Pipes, Serial communication resources, but for Files - not. If I am not mistaken...

      BTW: on Qt's bug tracker I found earlier a "suggestion ":https://bugreports.qt-project.org/browse/QTBUG-19345 to make asynchronous I/O for files... But there are many problems in case of implementation in *nix (if I correctly understood "it":http://tinyclouds.org/iocp-links.html)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MuldeR
        wrote on last edited by
        #3

        Should be possible to implement this with QtConcurrent, I think.
        @QByteArray myOp(QFile *aFile)
        {
        QByteArray data = aFile->readAll();
        return data;
        }

        /* ---------------- */

        main()
        {
        QFile aFile("in.txt");
        if (!aFile.open(QIODevice::ReadOnly)
        return;

        QFuture<QByteArray> future = QtConcurrent::run(myOp, &aFile);
        
        /* do something else*/
        
        QByteArray data = future.result()
        

        }@

        See also QFutureWatcher, if you want to be informed by a signal when the operation is done.

        My OpenSource software at: http://muldersoft.com/

        Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

        Go visit the coop: http://youtu.be/Jay...

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Using QtConcurrent is basically what I did to create async file I/O in our application. And yes, that works just fine.

          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