Skip to content

Commit b60922b

Browse files
author
florianlink
committed
fixed ref-counting in test
git-svn-id: http://svn.code.sf.net/p/pythonqt/code/trunk@394 ea8d5007-eb21-0410-b261-ccb3ea6e24a9
1 parent f9858cd commit b60922b

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

tests/PythonQtTests.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,11 +460,22 @@ public Q_SLOTS:
460460
QColor getQColor4(const QVariant& color) { _called = true; return qvariant_cast<QColor>(color); }
461461
QColor* getQColor5() { _called = true; static QColor c(1,2,3); return &c; }
462462

463-
PyObject* getPyObject(PyObject* obj) { _called = true; return obj; }
464-
PyObject* getPyObjectFromVariant(const QVariant& val) { _called = true; return PythonQtObjectPtr(val); };
463+
PyObject* getPyObject(PyObject* obj) {
464+
_called = true;
465+
// returned object needs to get an extra ref count!
466+
Py_XINCREF(obj);
467+
return obj;
468+
}
469+
470+
PyObject* getPyObjectFromVariant(const QVariant& val) {
471+
_called = true;
472+
PythonQtObjectPtr value = val;
473+
PyObject* obj = value.object();
474+
// returned object needs to get an extra ref count!
475+
Py_XINCREF(obj);
476+
return obj;
477+
};
465478
QVariant getPyObjectFromVariant2(const QVariant& val) { _called = true; return val; };
466-
// this does not yet work but is not required to work:
467-
//PyObject* getPyObjectFromPtr(const PythonQtObjectPtr& val) { _called = true; return val; };
468479

469480
//! testing pointer passing
470481
PythonQtTestSlotCallingHelper* getTestObject(PythonQtTestSlotCallingHelper* obj) { _called = true; return obj; }

0 commit comments

Comments
 (0)