4242#include " PythonQtStdDecorators.h"
4343#include " PythonQt.h"
4444#include " PythonQtClassInfo.h"
45+ #include " PythonQtConversion.h"
46+
4547#include < QCoreApplication>
4648
4749bool PythonQtStdDecorators::connect (QObject* sender, const QByteArray& signal, PyObject* callable)
@@ -175,39 +177,43 @@ QString PythonQtStdDecorators::tr(QObject* obj, const QByteArray& text, const QB
175177QObject* PythonQtStdDecorators::findChild (QObject* parent, PyObject* type, const QString& name)
176178{
177179 const QMetaObject* meta = NULL ;
178- const char * typeName = NULL ;
180+ QByteArray typeName;
179181
180182 if (PyObject_TypeCheck (type, &PythonQtClassWrapper_Type)) {
181183 meta = ((PythonQtClassWrapper*)type)->classInfo ()->metaObject ();
182184 } else if (PyObject_TypeCheck (type, &PythonQtInstanceWrapper_Type)) {
183185 meta = ((PythonQtInstanceWrapper*)type)->classInfo ()->metaObject ();
184- } else if (PyString_Check (type)) {
185- typeName = PyString_AsString (type);
186+ } else if (PyBytes_Check (type) || PyUnicode_Check (type)) {
187+ typeName = PythonQtConv::PyObjGetString (type). toUtf8 ( );
186188 }
187189
188- if (! typeName && !meta)
190+ if (typeName. isEmpty () && !meta) {
189191 return NULL ;
192+ }
190193
191194 return findChild (parent, typeName, meta, name);
192195}
193196
194197QList<QObject*> PythonQtStdDecorators::findChildren (QObject* parent, PyObject* type, const QString& name)
195198{
196199 const QMetaObject* meta = NULL ;
197- const char * typeName = NULL ;
200+ QByteArray typeName;
198201
199202 if (PyObject_TypeCheck (type, &PythonQtClassWrapper_Type)) {
200203 meta = ((PythonQtClassWrapper*)type)->classInfo ()->metaObject ();
201204 } else if (PyObject_TypeCheck (type, &PythonQtInstanceWrapper_Type)) {
202205 meta = ((PythonQtInstanceWrapper*)type)->classInfo ()->metaObject ();
203- } else if (PyString_Check (type)) {
204- typeName = PyString_AsString (type);
205206 }
207+ else if (PyBytes_Check (type) || PyUnicode_Check (type)) {
208+ typeName = PythonQtConv::PyObjGetString (type).toUtf8 ();
209+ }
210+
206211
207212 QList<QObject*> list;
208213
209- if (! typeName && !meta)
214+ if (typeName. isEmpty () && !meta) {
210215 return list;
216+ }
211217
212218 findChildren (parent, typeName, meta, name, list);
213219
@@ -217,20 +223,22 @@ QList<QObject*> PythonQtStdDecorators::findChildren(QObject* parent, PyObject* t
217223QList<QObject*> PythonQtStdDecorators::findChildren (QObject* parent, PyObject* type, const QRegExp& regExp)
218224{
219225 const QMetaObject* meta = NULL ;
220- const char * typeName = NULL ;
226+ QByteArray typeName;
221227
222228 if (PyObject_TypeCheck (type, &PythonQtClassWrapper_Type)) {
223229 meta = ((PythonQtClassWrapper*)type)->classInfo ()->metaObject ();
224230 } else if (PyObject_TypeCheck (type, &PythonQtInstanceWrapper_Type)) {
225231 meta = ((PythonQtInstanceWrapper*)type)->classInfo ()->metaObject ();
226- } else if (PyString_Check (type)) {
227- typeName = PyString_AsString (type);
232+ }
233+ else if (PyBytes_Check (type) || PyUnicode_Check (type)) {
234+ typeName = PythonQtConv::PyObjGetString (type).toUtf8 ();
228235 }
229236
230237 QList<QObject*> list;
231238
232- if (! typeName && !meta)
239+ if (typeName. isEmpty () && !meta) {
233240 return list;
241+ }
234242
235243 findChildren (parent, typeName, meta, regExp, list);
236244
0 commit comments