Skip to content

Commit 7781f0b

Browse files
author
florianlink
committed
updated docs
git-svn-id: http://svn.code.sf.net/p/pythonqt/code/trunk@385 ea8d5007-eb21-0410-b261-ccb3ea6e24a9
1 parent adf2040 commit 7781f0b

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/PythonQtDoc.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Qt framework</a>.
144144
- PythonQt currently does not support instanceof checks for Qt classes, except for the exact match and derived Python classes
145145
- QObject.emit to emit Qt signals from Python is not yet implemented but PythonQt allows to just emit a signal by calling it like a normal slot
146146
- PythonQt does not (yet) offer to add new signals/slots to Python/C++ objects and it does not create QMetaObjects for derived classes on the fly
147-
- Ownership of objects is a bit different in PythonQt, currently Python classes derived from a C++ class need to be manually referenced in Python to not get deleted too early (this will be fixed in a future version)
147+
- Ownership handling of objects is not as complete as in PySide and PyQt, especially in situations where the ownership is not clearly passed to C++ on the C++ API.
148148
- QStrings are always converted to unicode Python objects, QByteArray always stays a QByteArray and can be converted using QByteArray.data()
149149
- Qt methods that take an extra "bool* ok" parameter can be called passing PythonQt.BoolResult as parameter. In PyQt, a tuple is returned instead.
150150
@@ -420,6 +420,36 @@ yourCpp = None
420420
421421
\endcode
422422
423+
\section Ownership Ownership management
424+
425+
In PythonQt, each wrapped C++ object is either owned by Python or C++. When an object is created via a Python constructor,
426+
it is owned by Python by default. When an object is returned from a C++ API (e.g. a slot), it is owned by C++ by default.
427+
Since the Qt API contains various APIs that pass the ownership from/to other C++ objects, PythonQt needs to keep track of
428+
such API calls. This is archieved by annotating arguments and return values in wrapper slots with magic templates:
429+
430+
- PythonQtPassOwnershipToCPP
431+
- PythonQtPassOwnershipToPython
432+
- PythonQtNewOwnerOfThis
433+
434+
These annotation templates work for since C++ pointer types. In addition to that, they work for QList<AnyObject*>,
435+
to pass the ownership for each object in the list.
436+
437+
Examples:
438+
\code
439+
public slots:
440+
//! Pass ownership of return value to Python
441+
PythonQtPassOwnershipToPython<QGraphicsItem*> createNewItemOwnedByPython();
442+
443+
//! Pass ownership of item to C++
444+
void addItemToCPP(PythonQtPassOwnershipToPython<QGraphicsItem*> item);
445+
446+
//! Pass ownership of items to C++ (Note that the QList can't be a reference nor a pointer).
447+
void addItemToCPP(PythonQtPassOwnershipToPython<QList<QGraphicsItem*> > items);
448+
449+
//! Pass ownership of wrapped object to C++ if parent is != NULL
450+
void addItemParent(QGraphicsItem* wrappedObject, PythonQtNewOwnerOfThis<QGraphicsItem*> parent);
451+
\endcode
452+
423453
\page Building Building
424454
425455
PythonQt requires at least Qt 4.6.1 (for earlier Qt versions, you will need to run the pythonqt_generator, Qt 4.3 is the absolute minimum) and Python 2.6.x/2.7.x or Python 3.3 (or higher).

0 commit comments

Comments
 (0)