#include#include int main() { QScopedPointer ptr(new int(42)); std::cout << *ptr << std::endl; // ptr will be automatically deleted when it goes out of scope return 0; }
#includeIn this example, a QScopedPointer is used to manage a QFile object that is opened for reading. When the QScopedPointer goes out of scope, it automatically closes and deletes the file. Overall, QScopedPointer is a useful tool for managing dynamically allocated objects in a safe and efficient way. It is a part of the Qt library, which is a comprehensive set of tools for building cross-platform applications in C++.#include int main() { QScopedPointer file(new QFile("test.txt")); if (file->open(QIODevice::ReadOnly)) { // read data from the file } return 0; }