#include#include int main() { QFile file("test.txt"); QObject* parent = new QObject(); // Set the parent for the file object file.setParent(parent); // Do some work with the file... // When the parent object is deleted, the file object will be deleted too delete parent; }
#includeThese examples use the Qt core library.#include int main() { QFile file("test.txt"); QBuffer buffer; // Set the parent for the file object using the buffer object file.setParent(&buffer); // Do some work with the file... // When the buffer object is deleted, the file object will be deleted too }