Asynchronous file IO
Are there any facilities for asynchronous file IO in Qt?
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)
Should be possible to implement this with QtConcurrent, I think.
@QByteArray myOp(QFile *aFile)
QByteArray data = aFile->readAll();
/* ---------------- */
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.
Using QtConcurrent is basically what I did to create async file I/O in our application. And yes, that works just fine.