@@ -81,6 +81,7 void PythonQt::init(int flags, const QByteArray& pythonQtModuleName) | |||
|
81 | 81 | PythonQt_init_QtCoreBuiltin(NULL); |
|
82 | 82 | PythonQt_init_QtGuiBuiltin(NULL); |
|
83 | 83 | |
|
84 | PythonQtRegisterToolClassesTemplateConverter(QByteArray); | |
|
84 | 85 | PythonQtRegisterToolClassesTemplateConverter(QDate); |
|
85 | 86 | PythonQtRegisterToolClassesTemplateConverter(QTime); |
|
86 | 87 | PythonQtRegisterToolClassesTemplateConverter(QDateTime); |
@@ -146,10 +146,11 PyObject* PythonQtConv::ConvertQtValueToPythonInternal(int type, const void* dat | |||
|
146 | 146 | return PyLong_FromLongLong(*((qint64*)data)); |
|
147 | 147 | case QMetaType::ULongLong: |
|
148 | 148 | return PyLong_FromUnsignedLongLong(*((quint64*)data)); |
|
149 | case QMetaType::QByteArray: { | |
|
150 | QByteArray* v = (QByteArray*) data; | |
|
151 | return PyString_FromStringAndSize(*v, v->size()); | |
|
152 | } | |
|
149 | // implicit conversion from QByteArray to str has been removed: | |
|
150 | //case QMetaType::QByteArray: { | |
|
151 | // QByteArray* v = (QByteArray*) data; | |
|
152 | // return PyString_FromStringAndSize(*v, v->size()); | |
|
153 | // } | |
|
153 | 154 | case QMetaType::QVariantMap: |
|
154 | 155 | return PythonQtConv::QVariantMapToPyObject(*((QVariantMap*)data)); |
|
155 | 156 | case QMetaType::QVariantList: |
@@ -689,6 +690,7 QString PythonQtConv::PyObjGetString(PyObject* val, bool strict, bool& ok) { | |||
|
689 | 690 | } |
|
690 | 691 | |
|
691 | 692 | QByteArray PythonQtConv::PyObjGetBytes(PyObject* val, bool /*strict*/, bool& ok) { |
|
693 | // TODO: support buffer objects in general | |
|
692 | 694 | QByteArray r; |
|
693 | 695 | ok = true; |
|
694 | 696 | if (val->ob_type == &PyString_Type) { |
@@ -146,7 +146,7 | |||
|
146 | 146 | - QObject.emit to emit Qt signals from Python is not yet implemented but PythonQt allows to just emit a signal by calling it |
|
147 | 147 | - PythonQt does not (yet) offer to add new signals to Python/C++ objects |
|
148 | 148 | - 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) |
|
149 |
- QString |
|
|
149 | - QStrings are always converted to unicode Python objects (PyQt returns QString instead), we prefered to return Python strings. | |
|
150 | 150 | - Probably there are lots of details that differ, I do not know PyQt that well to list them all. |
|
151 | 151 | |
|
152 | 152 | \section Interface |
@@ -566,6 +566,17 static QString getStringFromObject(PythonQtInstanceWrapper* wrapper) { | |||
|
566 | 566 | static PyObject * PythonQtInstanceWrapper_str(PyObject * obj) |
|
567 | 567 | { |
|
568 | 568 | PythonQtInstanceWrapper* wrapper = (PythonQtInstanceWrapper*)obj; |
|
569 | ||
|
570 | // QByteArray should be directly returned as a str | |
|
571 | if (wrapper->classInfo()->metaTypeId()==QVariant::ByteArray) { | |
|
572 | QByteArray* b = (QByteArray*) wrapper->_wrappedPtr; | |
|
573 | if (b->data()) { | |
|
574 | return PyString_FromStringAndSize(b->data(), b->size()); | |
|
575 | } else { | |
|
576 | return PyString_FromString(""); | |
|
577 | } | |
|
578 | } | |
|
579 | ||
|
569 | 580 | const char* typeName = obj->ob_type->tp_name; |
|
570 | 581 | QObject *qobj = wrapper->_obj; |
|
571 | 582 | QString str = getStringFromObject(wrapper); |
General Comments 0
You need to be logged in to leave comments.
Login now