diff options
Diffstat (limited to 'PySide/QtCore/qbytearray_conversions.h')
-rw-r--r-- | PySide/QtCore/qbytearray_conversions.h | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/PySide/QtCore/qbytearray_conversions.h b/PySide/QtCore/qbytearray_conversions.h index daa16099f..d776d82c4 100644 --- a/PySide/QtCore/qbytearray_conversions.h +++ b/PySide/QtCore/qbytearray_conversions.h @@ -11,19 +11,29 @@ inline bool Converter<QByteArray>::isConvertible(PyObject* pyObj) return true; SbkObjectType* shiboType = reinterpret_cast<SbkObjectType*>(SbkType< ::QByteArray >()); return Shiboken::Converter<const char *>::checkType(pyObj) + || PyBytes_Check(pyObj) || (ObjectType::isExternalConvertible(shiboType, pyObj)); } inline QByteArray Converter<QByteArray>::toCpp(PyObject* pyObj) { - if (pyObj == Py_None) + if (pyObj == Py_None) { return 0; - else if (PyObject_TypeCheck(pyObj, SbkType<QByteArray>())) + } else if (PyObject_TypeCheck(pyObj, SbkType<QByteArray>())) { return *Converter<QByteArray*>::toCpp(pyObj); - else if (PyString_Check(pyObj)) - return QByteArray(PyString_AS_STRING(pyObj), PyString_GET_SIZE(pyObj)); - else + } else if (PyBytes_Check(pyObj)) { + return QByteArray(PyBytes_AS_STRING(pyObj), PyBytes_GET_SIZE(pyObj)); + } else if (PyUnicode_Check(pyObj)) { + Shiboken::AutoDecRef data(PyUnicode_AsASCIIString(pyObj)); + if (!data.isNull()) + return QByteArray(PyBytes_AsString(data.object()), PyBytes_GET_SIZE(data.object())); + else + return QByteArray(); + } else if (Shiboken::String::check(pyObj)) { + return QByteArray(Shiboken::String::toCString(pyObj)); + } else { return ValueTypeConverter<QByteArray>::toCpp(pyObj); + } } inline PyObject* Converter<QByteArray>::toPython(const ::QByteArray& cppObj) |