Fixed bug with refcount on PyObject args during signal/slot emission.
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org>
Lauro Moura <lauro.neto@openbossa.org>
This commit is contained in:
parent
2de4b93859
commit
de4a1a10b0
2 changed files with 54 additions and 7 deletions
|
|
@ -59,7 +59,8 @@
|
||||||
struct PyObjectWrapper
|
struct PyObjectWrapper
|
||||||
{
|
{
|
||||||
PyObject* m_me;
|
PyObject* m_me;
|
||||||
PyObjectWrapper(PyObject* me) : m_me(me) {}
|
PyObjectWrapper(const PyObjectWrapper &other) : m_me(other.m_me) {}
|
||||||
|
PyObjectWrapper(PyObject* me) : m_me(me) { Py_INCREF(m_me); }
|
||||||
PyObjectWrapper() : m_me(Py_None) {}
|
PyObjectWrapper() : m_me(Py_None) {}
|
||||||
operator PyObject*() const { return m_me; }
|
operator PyObject*() const { return m_me; }
|
||||||
};
|
};
|
||||||
|
|
@ -310,7 +311,7 @@ bool SignalManager::emitSignal(QObject* source, const char* signal, PyObject* ar
|
||||||
else
|
else
|
||||||
return emitNormalSignal(source, signalIndex, signal, args, argTypes);
|
return emitNormalSignal(source, signalIndex, signal, args, argTypes);
|
||||||
}
|
}
|
||||||
qWarning() << "Signal" << signal << "not found, probably a typo or you are emitting a dynamic signal that has never been used in a connection until now.";
|
qDebug() << "Signal" << signal << "not found, probably a typo or you are emitting a dynamic signal that has never been used in a connection until now.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from PySide.QtCore import QObject, SIGNAL, SLOT
|
from PySide.QtCore import QObject, SIGNAL, SLOT, Qt
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from PySide.QtGui import QSpinBox, QApplication, QWidget
|
from PySide.QtGui import QSpinBox, QApplication, QWidget
|
||||||
|
|
@ -18,18 +18,64 @@ class Dummy(QObject):
|
||||||
def callDummy(self):
|
def callDummy(self):
|
||||||
self.emit(SIGNAL("dummy(PyObject)"), "PyObject")
|
self.emit(SIGNAL("dummy(PyObject)"), "PyObject")
|
||||||
|
|
||||||
|
def callDummy2(self):
|
||||||
|
lst = []
|
||||||
|
lst.append("item1")
|
||||||
|
lst.append("item2")
|
||||||
|
lst.append("item3")
|
||||||
|
self.emit(SIGNAL("dummy2(PyObject, PyObject)"), "PyObject0", lst)
|
||||||
|
|
||||||
class PyObjectType(unittest.TestCase):
|
|
||||||
|
class PyObjectType(UsesQApplication):
|
||||||
def mySlot(self, arg):
|
def mySlot(self, arg):
|
||||||
self.assertEqual(arg, "PyObject")
|
self.assertEqual(arg, "PyObject")
|
||||||
self.called = True
|
self.called = True
|
||||||
|
self.callCount += 1
|
||||||
|
|
||||||
def testType(self):
|
def mySlot2(self, arg0, arg1):
|
||||||
self.called = False
|
self.assertEqual(arg0, "PyObject0")
|
||||||
|
self.assertEqual(arg1[0], "item1")
|
||||||
|
self.assertEqual(arg1[1], "item2")
|
||||||
|
self.assertEqual(arg1[2], "item3")
|
||||||
|
self.callCount += 1
|
||||||
|
if self.running:
|
||||||
|
self.app.quit()
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(PyObjectType, self).setUp()
|
||||||
|
self.callCount = 0
|
||||||
|
self.running = False
|
||||||
|
|
||||||
|
def testWithOneArg(self):
|
||||||
o = Dummy()
|
o = Dummy()
|
||||||
o.connect(SIGNAL("dummy(PyObject)"), self.mySlot)
|
o.connect(SIGNAL("dummy(PyObject)"), self.mySlot)
|
||||||
o.callDummy()
|
o.callDummy()
|
||||||
self.assert_(self.called)
|
self.assertEqual(self.callCount, 1)
|
||||||
|
|
||||||
|
def testWithTwoArg(self):
|
||||||
|
o = Dummy()
|
||||||
|
o.connect(SIGNAL("dummy2(PyObject,PyObject)"), self.mySlot2)
|
||||||
|
o.callDummy2()
|
||||||
|
self.assertEqual(self.callCount, 1)
|
||||||
|
|
||||||
|
def testAsyncSignal(self):
|
||||||
|
self.called = False
|
||||||
|
self.running = True
|
||||||
|
o = Dummy()
|
||||||
|
o.connect(SIGNAL("dummy2(PyObject,PyObject)"), self.mySlot2, Qt.QueuedConnection)
|
||||||
|
o.callDummy2()
|
||||||
|
self.app.exec_()
|
||||||
|
self.assertEqual(self.callCount, 1)
|
||||||
|
|
||||||
|
def testTwice(self):
|
||||||
|
self.called = False
|
||||||
|
self.running = True
|
||||||
|
o = Dummy()
|
||||||
|
o.connect(SIGNAL("dummy2(PyObject,PyObject)"), self.mySlot2, Qt.QueuedConnection)
|
||||||
|
o.callDummy2()
|
||||||
|
o.callDummy2()
|
||||||
|
self.app.exec_()
|
||||||
|
self.assertEqual(self.callCount, 2)
|
||||||
|
|
||||||
class PythonSigSlot(unittest.TestCase):
|
class PythonSigSlot(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue