diff options
author | Jason Barron <jbarron@trolltech.com> | 2009-08-04 11:17:47 (GMT) |
---|---|---|
committer | Jason Barron <jbarron@trolltech.com> | 2009-08-04 11:17:47 (GMT) |
commit | be212bf108e71ba3b5b75802b1f4de6613ba315c (patch) | |
tree | c541ad12e8698f04e8fe386c2e1b94e8baca6c1b /doc | |
parent | 67ae1b0dac175f48875507f3187ed49276a29ddf (diff) | |
parent | e6bb00250b321b149dd80259dc4f479088d5949b (diff) | |
download | Qt-be212bf108e71ba3b5b75802b1f4de6613ba315c.zip Qt-be212bf108e71ba3b5b75802b1f4de6613ba315c.tar.gz Qt-be212bf108e71ba3b5b75802b1f4de6613ba315c.tar.bz2 |
Merge commit 'origin/master'
Conflicts:
src/corelib/global/qglobal.h
src/corelib/kernel/qmetatype.cpp
src/corelib/kernel/qobject.cpp
src/corelib/thread/qthread_unix.cpp
src/gui/graphicsview/qgraphicssceneevent.h
src/gui/itemviews/qheaderview.h
src/gui/kernel/qapplication_qws.cpp
src/gui/kernel/qgesture.h
src/gui/kernel/qgesturerecognizer.h
src/gui/painting/qpaintengine_raster.cpp
src/network/access/qhttpnetworkreply.cpp
src/network/access/qnetworkcookie.h
src/network/socket/qnativesocketengine_unix.cpp
Diffstat (limited to 'doc')
-rw-r--r-- | doc/src/qmake-manual.qdoc | 32 | ||||
-rw-r--r-- | doc/src/snippets/code/doc_src_qmake-manual.qdoc | 6 | ||||
-rw-r--r-- | doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp | 21 | ||||
-rw-r--r-- | doc/src/symbian-exceptionsafety.qdoc | 78 |
4 files changed, 119 insertions, 18 deletions
diff --git a/doc/src/qmake-manual.qdoc b/doc/src/qmake-manual.qdoc index 2985b89..d752811 100644 --- a/doc/src/qmake-manual.qdoc +++ b/doc/src/qmake-manual.qdoc @@ -1382,14 +1382,36 @@ \snippet doc/src/snippets/code/doc_src_qmake-manual.qdoc 128 - In Symbian, dependencies to other packages can also be created using - this variable. The strings defined as dependencies are not parsed by - qmake, so they should be in a format understood by Symbian package - generation tools. Please consult Symbian documentation for correct syntax. + In Symbian, generic PKG file content can also be specified with this + variable. You can use either \c pkg_prerules or \c pkg_postrules to + pass raw data to PKG file. The strings in \c pkg_prerules are added before + package-body and \c pkg_postrules after. The strings defined in + \c pkg_postrules or \c pkg_prerules are not parsed by qmake, so they + should be in a format understood by Symbian package generation tools. + Please consult Symbian documentation for correct syntax. - For example: + For example, to deploy DLL and add a new dependency: \snippet doc/src/snippets/code/doc_src_qmake-manual.qdoc 140 + + Please note that \c pkg_prerules can also replace default statements in + pkg file. If no pkg_prerules is defined, qmake makes sure that PKG file + syntax is correct and it contains all mandatory statements such as: + + \list + \o languages, for example \BR + &EN,FR + \o package-header, for example \BR + #{"MyApp-EN", "MyApp-FR"}, (0x1000001F), 1, 2, 3, TYPE=SA + \o localized and unique vendor, for example \BR + %{"Vendor-EN", ..., "Vendor-FR"} + :"Unique vendor name" + \endlist + + If you decide to override any of these statements, you need to pay + attention that also other statements stay valid. For example if you + override languages statement, you must override also package-header + statement and all other statements which are language specific. In Symbian, the \c default_deployment item specifies default platform dependencies. It can be overwritten if a more diff --git a/doc/src/snippets/code/doc_src_qmake-manual.qdoc b/doc/src/snippets/code/doc_src_qmake-manual.qdoc index 753d560..64dc559 100644 --- a/doc/src/snippets/code/doc_src_qmake-manual.qdoc +++ b/doc/src/snippets/code/doc_src_qmake-manual.qdoc @@ -885,14 +885,14 @@ MMP_RULES += myIfdefBlock //! [140] somelib.sources = somelib.dll somelib.path = \sys\bin -somelib.depends = "(0x12345678), 2, 2, 0, {\"Some Package\"}" \ +somelib.pkg_prerules = "(0x12345678), 2, 2, 0, {\"Some Package\"}" \ "(0x87654321), 1, *, * ~ 2, 2, 0, {\"Some Other Package\"}" -justdep.depends = "(0xAAAABBBB), 0, 2, 0, {\"My Framework\"}" +justdep.pkg_prerules = "(0xAAAABBBB), 0, 2, 0, {\"My Framework\"}" DEPLOYMENT += somelib justdep //! [140] //! [141] -default_deployment.depends = "[0x11223344],0,0,0,{\"SomeSpecificDeviceID\"}" +default_deployment.pkg_prerules = "[0x11223344],0,0,0,{\"SomeSpecificDeviceID\"}" //! [141] //! [142] diff --git a/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp b/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp index 7de42b7..b625eb2 100644 --- a/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp +++ b/doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp @@ -27,6 +27,7 @@ void myFunction(bool useSubClass) //! [1] void myFunction(bool useSubClass) { + // assuming that MyClass has a virtual destructor QScopedPointer<MyClass> p(useSubClass ? new MyClass() : new MySubClass); QScopedPointer<QIODevice> device(handsOverOwnership()); @@ -80,3 +81,23 @@ private: // generate them. }; //! [4] + +//! [5] +// this QScopedPointer deletes its data using the delete[] operator: +QScopedPointer<int, QScopedPointerArrayDeleter<int> > arrayPointer(new int[42]); + +// this QScopedPointer frees its data using free(): +QScopedPointer<int, QScopedPointerPodDeleter<int> > podPointer(reinterpret_cast<int *>(malloc(42))); + +// this struct calls "myCustomDeallocator" to delete the pointer +struct ScopedPointerCustomDeleter +{ + static inline void cleanup(MyCustomClass *pointer) + { + myCustomDeallocator(pointer); + } +}; + +// QScopedPointer using a custom deleter: +QScopedPointer<MyCustomClass, ScopedPointerCustomDeleter> customPointer(new MyCustomClass); +//! [5] diff --git a/doc/src/symbian-exceptionsafety.qdoc b/doc/src/symbian-exceptionsafety.qdoc index 56b28c9..df18031 100644 --- a/doc/src/symbian-exceptionsafety.qdoc +++ b/doc/src/symbian-exceptionsafety.qdoc @@ -80,11 +80,16 @@ Symbian leaves to standard C++ exceptions. The following help is provided: \list - \o \l qt_translateSymbianErrorToException() takes a Symbian + \o \l qt_throwIfError() takes a Symbian error code and throws an appropriate exception to represent it. This will do nothing if the error code is not in fact an error. The function is equivalent to Symbian's \c User::LeaveIfError. - \o \l QT_TRANSLATE_SYMBIAN_LEAVE_TO_EXCEPTION() takes a Symbian leaving + \o \l q_check_ptr() takes a pointer and throws a std::bad_alloc + exception if it is 0, otherwise the pointer is returned. This can be + used to check the success of a non-throwing allocation, eg from + \c malloc(). The function is equivalent to Symbian's \c + User::LeaveIfNull. + \o \l QT_TRAP_THROWING() takes a Symbian leaving code fragment f and runs it under a trap harness converting any resulting error into an exception. \o \c TRAP and \c TRAPD from the Symbian libraries can be used to convert @@ -94,16 +99,35 @@ \code HBufC* buf=0; // this will throw a std::bad_alloc because we've asked for too much memory - QT_TRANSLATE_SYMBIAN_LEAVE_TO_EXCEPTION(buf = HBufC::NewL(100000000)); + QT_TRAP_THROWING(buf = HBufC::NewL(100000000)); _LIT(KStr,"abc"); TInt pos = KStr().Locate('c'); // pos is a good value, >= 0, so no exception is thrown - qt_translateSymbianErrorToException(pos); + qt_throwIfError(pos); pos = KStr().Locate('d'); // pos == KErrNotFound, so this throws an exception - qt_translateSymbianErrorToException(pos); + qt_throwIfError(pos); + + // we are asking for a lot of memory, HBufC::New may return NULL, so check it + HBufC *buffer = q_check_ptr(HBufC::New(1000000)); + \endcode + + \section2 Be careful with new and CBase + + When writing Qt code, \c new will normally throw a \c std::bad_alloc if the + allocation fails. However this may not happen if the object being created + has its own \c {operator new}. For example, CBase and derived classes have + their own \c {operator new} which returns 0 and the \c {new(ELeave)} + overload for a leaving \c {operator new}, neither of which does what we want. + When using 2-phase construction of CBase derived objects, use \c new and + \l q_check_ptr(). + + \oldcode + CFbsBitmap* fbsBitmap = new(ELeave) CFbsBitmap; + \newcode + CFbsBitmap* fbsBitmap = q_check_ptr(new CFbsBitmap); \endcode \section1 Qt called from Symbian @@ -113,18 +137,18 @@ provided: \list - \o \l qt_translateExceptionToSymbianError() - + \o \l qt_exception2SymbianError() - this takes a standard exception and gives an appropriate Symbian error code. If no mapping is known for the exception type, \c KErrGeneral is returned. - \o \l qt_translateExceptionToSymbianErrorL() - + \o \l qt_exception2SymbianLeaveL() - this takes a standard exception and generates an appropriate Symbian leave. - \o \l QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_ERROR() - this macro + \o \l QT_TRYCATCH_ERROR() - this macro takes the standard C++ code fragment \c f, catches any std::exceptions thrown from it, and sets err to the corresponding Symbian error code. err is set to \c KErrNone otherwise. - \o \l QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE() - this macro takes the + \o \l QT_TRYCATCH_LEAVING() - this macro takes the standard C++ code fragment \c f, catches any std::exceptions thrown from it, and throws a corresponding Symbian leave. \endlist @@ -133,7 +157,7 @@ TInt DoTickL() // called from an active object RunL, ie Symbian leaves expected { // without the translation to Symbian Leave, we get a USER:0 panic - QT_TRANSLATE_EXCEPTION_TO_SYMBIAN_LEAVE({ + QT_TRYCATCH_LEAVING({ int* x = new int[100000000]; // compiled as Qt code, will throw std::bad_alloc delete [] x; }); @@ -180,4 +204,38 @@ Now the exception generating functions are separated from the leaving functions. + + \section1 Advanced technique + When using Symbian APIs in Qt code, you may find that Symbian leaving + code and Qt exception throwing code are just too mixed up to have + them interoperate through barriers. In some circumstances you can allow + code to both leave and throw exceptions. But you must be aware of the + following issues: + + \list + \o Depending on whether a leave or exception is thrown, or a normal + exit happens, the cleanup order will vary. If the code leaves, + cleanup stack cleanup will happen first. On an exception however, + cleanup stack cleanup will happen last. + \o There must not be any destructor dependencies between different + code styles. That is, you must not have symbian objects using Qt + objects in their destructors, and vice versa. This is because the + cleanup order varies, and may result in objects being used after + they are deleted. + \o The cleanup stack must not refer to any stack based object. For + instance, in Symbian you may use \c CleanupClosePushL() to push + stack based R-classes onto the cleanup stack. However if the + stack has unwound due to an exception before the cleanup stack + cleanup happens, stack based objects will now be invalid. + Instead of using the cleanup stack, consider Symbian's new + \c LManagedHandle<> (or a custom cleanup object) to tie R-class + cleanup to the stack. + \o Mixed throwing code must be called within both a TRAP and a + try/catch harness. Standard exceptions must not propagate to + the TRAP and cleanup stack cleanup will only happen if a leave + is thrown, so the correct pattern is either \c {TRAPD(err, + QT_TRYCATCH_LEAVING( f ));} or \c {QT_TRAP_THROWING( + QT_TRYCATCH_LEAVING( f ));}, depending if you want an error + code or exception as a result. + \endlist */ |