#include#include int main() { QFile file("example.txt"); if(file.open(QIODevice::WriteOnly)) { QTextStream out(&file); out << "Hello World!"; file.flush(); file.close(); } return 0; }
#includeIn this example, a QTcpSocket reads data from a connection and stores it in a QByteArray. The data is then written to the file "example.txt", and the flush() method is used to immediately write the data to the file system. The QFile and QTcpSocket classes are part of the QtCore package library in Qt framework.#include int main() { QTcpSocket socket; QFile file("example.txt"); if(file.open(QIODevice::WriteOnly)) { socket.setSocketOption(QAbstractSocket::LowDelayOption, 1); QByteArray data = socket.readAll(); file.write(data); file.flush(); file.close(); } return 0; }