#includeint main () { QFile file("output.txt"); if (file.open(QIODevice::WriteOnly)) { QTextStream stream(&file); stream << "Hello, World!" << endl; file.close(); // Closing the file after writing the text } return 0; }
#includeIn this example, we create a QTcpSocket object and connect it to a local host on port 80. We then use the readAll() function to read data from the socket and store it in a QByteArray. Finally, we close the socket using the close() function to release its resources. Package/Library: Qt Network module.int main() { QTcpSocket socket; socket.connectToHost("localhost", 80); if (socket.waitForConnected()) { QByteArray block = socket.readAll(); socket.close(); // Closing the socket after reading the data } return 0; }