Asynchronous file IO
-
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();
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.