diff --git a/src/PythonQt.cpp b/src/PythonQt.cpp index 6897c9f..6bd2dc2 100644 --- a/src/PythonQt.cpp +++ b/src/PythonQt.cpp @@ -1137,7 +1137,7 @@ static PyObject *PythonQt_SIGNAL(PyObject * /*type*/, PyObject *args) return NULL; } // we do not prepend 0,1 or 2, why should we? - return PyString_FromString(value); + return PyString_FromString(QByteArray("2") + value); } static PyObject *PythonQt_SLOT(PyObject * /*type*/, PyObject *args) @@ -1147,7 +1147,7 @@ static PyObject *PythonQt_SLOT(PyObject * /*type*/, PyObject *args) return NULL; } // we do not prepend 0,1 or 2, why should we? - return PyString_FromString(value); + return PyString_FromString(QByteArray("1") + value); } static PyMethodDef PythonQt_Qt_methods[] = { diff --git a/src/PythonQtDoc.h b/src/PythonQtDoc.h index 71fb754..9977eca 100644 --- a/src/PythonQtDoc.h +++ b/src/PythonQtDoc.h @@ -143,7 +143,6 @@ - PythonQt is not as Pythonic as PyQt in many details (e.g. operator mapping, pickling, translation support, ...) and it is mainly thought for embedding and intercommunication between Qt/Cpp and Python - PythonQt allows to communicate in both directions, e.g. calling a Python object from C++ AND calling a C++ method from Python, while PyQt only handles the Python->C++ direction - PythonQt offers properties as Python attributes, while PyQt offers them as setter/getter methods (e.g. QWidget.width is a property in PythonQt and a method in PyQt) - - PythonQt offer QtCore.SIGNAL() and QtCore.SLOT() methods for compability, but no 0/1/3 is prepended - PythonQt does not support instanceof checks for Qt classes, except for the exact match and derived Python classes - QObject.emit to emit Qt signals from Python is not yet implemented - PythonQt does not offer to add new signals to Python/C++ objects diff --git a/src/PythonQtStdDecorators.cpp b/src/PythonQtStdDecorators.cpp index fe111b6..d604613 100644 --- a/src/PythonQtStdDecorators.cpp +++ b/src/PythonQtStdDecorators.cpp @@ -46,8 +46,14 @@ bool PythonQtStdDecorators::connect(QObject* sender, const QByteArray& signal, PyObject* callable) { - QByteArray signalTmp("2"); - signalTmp += signal; + QByteArray signalTmp; + char first = signal.at(0); + if (first>='0' && first<='9') { + signalTmp = signal; + } else { + signalTmp = "2" + signal; + } + if (sender) { return PythonQt::self()->addSignalHandler(sender, signalTmp, callable); } else { @@ -59,21 +65,35 @@ bool PythonQtStdDecorators::connect(QObject* sender, const QByteArray& signal, Q { bool r = false; if (sender && receiver) { - QByteArray signalTmp("2"); - signalTmp += signal; - QByteArray slotTmp("1"); - slotTmp += slot; - if (receiver) { - r = QObject::connect(sender, signalTmp, receiver, slotTmp); + QByteArray signalTmp; + char first = signal.at(0); + if (first>='0' && first<='9') { + signalTmp = signal; + } else { + signalTmp = "2" + signal; + } + + QByteArray slotTmp; + first = slot.at(0); + if (first>='0' && first<='9') { + slotTmp = slot; + } else { + slotTmp = "1" + slot; } + r = QObject::connect(sender, signalTmp, receiver, slotTmp); } return r; } bool PythonQtStdDecorators::disconnect(QObject* sender, const QByteArray& signal, PyObject* callable) { - QByteArray signalTmp("2"); - signalTmp += signal; + QByteArray signalTmp; + char first = signal.at(0); + if (first>='0' && first<='9') { + signalTmp = signal; + } else { + signalTmp = "2" + signal; + } if (sender) { return PythonQt::self()->removeSignalHandler(sender, signalTmp, callable); } else { @@ -85,13 +105,23 @@ bool PythonQtStdDecorators::disconnect(QObject* sender, const QByteArray& signal { bool r = false; if (sender && receiver) { - QByteArray signalTmp("2"); - signalTmp += signal; - QByteArray slotTmp("1"); - slotTmp += slot; - if (receiver) { - r = QObject::disconnect(sender, signalTmp, receiver, slotTmp); + QByteArray signalTmp; + char first = signal.at(0); + if (first>='0' && first<='9') { + signalTmp = signal; + } else { + signalTmp = "2" + signal; + } + + QByteArray slotTmp; + first = slot.at(0); + if (first>='0' && first<='9') { + slotTmp = slot; + } else { + slotTmp = "1" + slot; } + + r = QObject::disconnect(sender, signalTmp, receiver, slotTmp); } return r; }