Accessing files using Qt

Files are a specialization of a generalized notion—that of a byte stream that resides somewhere else. Qt encapsulates the more generalized notion of byte streams in its QIODevice class, which is the parent class for QFile as well as network I/O classes such as QTcpSocket. We don't directly create a QIODevice instance, of course, but instead create a subclass such as QFile and then work with the QFile instance directly to read from and write to the file.

Tip

Files and network access usually take time, and thus, your applications shouldn't work with them on the main thread. Consider creating a subclass of QThread to perform I/O operations such as reading from files or accessing the network.

To begin working with a file, we ...

Get Application Development with Qt Creator - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.