diff options
author | Robert Griebl <rgriebl@trolltech.com> | 2009-06-10 11:46:23 (GMT) |
---|---|---|
committer | Robert Griebl <rgriebl@trolltech.com> | 2009-06-10 11:46:23 (GMT) |
commit | 7604f8087f88171ef933d8ae08f501467e647338 (patch) | |
tree | 51d071f462ed48d0b25884d9f62b8ba11c5dff13 /doc | |
parent | 8c265860b41214daade7c8a28237c1e07ea71a3c (diff) | |
download | Qt-7604f8087f88171ef933d8ae08f501467e647338.zip Qt-7604f8087f88171ef933d8ae08f501467e647338.tar.gz Qt-7604f8087f88171ef933d8ae08f501467e647338.tar.bz2 |
Make Qt exception safer.
Squashed commit of the branch haralds-haralds-qt-s60-topics/topic/exceptions,
which also contains the full history.
Rev-By: Harald Fernengel
Rev-By: Ralf Engels
Diffstat (limited to 'doc')
-rw-r--r-- | doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp b/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp new file mode 100644 index 0000000..05377dd --- /dev/null +++ b/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp @@ -0,0 +1,64 @@ +//! [0] +void myFunction(bool useSubClass) +{ + MyClass *p = useSubClass ? new MyClass() : new MySubClass; + QIODevice *device = handsOverOwnership(); + QIODevi + + if (m_value > 3) { + delete p; + delete device; + return; + } + + try { + process(device); + } + catch (...) { + delete p; + delete device; + throw; + } + + delete p; + delete device; +} +//! [0] + +//! [1] +void myFunction(bool useSubClass) +{ + QScopedPointer<MyClass> p(useSubClass ? new MyClass() : new MySubClass); + QScopedPointer<QIODevice> device(handsOverOwnership()); + + if (m_value > 3) + return; + + process(device); +} +//! [1] + +//! [2] + const QWidget *const p = new QWidget(); + // is equivalent to: + const QScopedPointer<const QWidget> p(new QWidget()); + + QWidget *const p = new QWidget(); + // is equivalent to: + const QScopedPointer<QWidget> p(new QWidget()); + + QWidget *const p = new QWidget(); + // is equivalent to: + const QScopedPointer<QWidget> p(new QWidget()); + + const QWidget *p = new QWidget(); + // is equivalent to: + QScopedPointer<const QWidget> p(new QWidget()); + +//! [2] + +//! [3] +if (scopedPointer) { + ... +} +//! [3] |