@@ -830,7 +830,7 @@ PythonQtObjectPtr PythonQt::lookupObject(PyObject* module, const QString& name)
830
830
QByteArray b;
831
831
for (QStringList::ConstIterator i = l.begin (); i!=l.end () && p; ++i) {
832
832
prev = p;
833
- b = (*i). toLatin1 ( );
833
+ b = QStringToPythonEncoding (*i);
834
834
if (PyDict_Check (p)) {
835
835
p = PyDict_GetItemString (p, b.data ());
836
836
} else {
@@ -850,7 +850,7 @@ PythonQtObjectPtr PythonQt::getMainModule() {
850
850
PythonQtObjectPtr PythonQt::importModule (const QString& name)
851
851
{
852
852
PythonQtObjectPtr mod;
853
- mod.setNewRef (PyImport_ImportModule (name. toLatin1 (). constData ( )));
853
+ mod.setNewRef (PyImport_ImportModule (QStringToPythonCharPointer (name )));
854
854
return mod;
855
855
}
856
856
@@ -903,7 +903,7 @@ QVariant PythonQt::evalScript(PyObject* object, const QString& script, int start
903
903
dict = object;
904
904
}
905
905
if (dict) {
906
- p.setNewRef (PyRun_String (script. toLatin1 (). data ( ), start, dict, dict));
906
+ p.setNewRef (PyRun_String (QStringToPythonCharPointer (script ), start, dict, dict));
907
907
}
908
908
if (p) {
909
909
result = PythonQtConv::PyObjToQVariant (p);
@@ -920,7 +920,7 @@ QVariant PythonQt::evalScript(const QString& script, PyObject* globals, PyObject
920
920
PythonQtObjectPtr p;
921
921
clearError ();
922
922
if (globals) {
923
- p.setNewRef (PyRun_String (script. toLatin1 (). data ( ), start, globals, locals ? locals : globals));
923
+ p.setNewRef (PyRun_String (QStringToPythonCharPointer (script ), start, globals, locals ? locals : globals));
924
924
if (p) {
925
925
result = PythonQtConv::PyObjToQVariant (p);
926
926
} else {
@@ -968,7 +968,7 @@ PythonQtObjectPtr PythonQt::createModuleFromScript(const QString& name, const QS
968
968
scriptCode = " \n " ;
969
969
}
970
970
PythonQtObjectPtr pycode;
971
- pycode.setNewRef (Py_CompileString (( char *) scriptCode. toLatin1 (). data ( ), " " , Py_file_input));
971
+ pycode.setNewRef (Py_CompileString (QStringToPythonCharPointer ( scriptCode), " " , Py_file_input));
972
972
PythonQtObjectPtr module = _p->createModule (name, pycode);
973
973
return module ;
974
974
}
@@ -983,31 +983,31 @@ PythonQtObjectPtr PythonQt::createUniqueModule()
983
983
void PythonQt::addObject (PyObject* object, const QString& name, QObject* qObject)
984
984
{
985
985
if (PyModule_Check (object)) {
986
- PyModule_AddObject (object, name. toLatin1 (). data ( ), _p->wrapQObject (qObject));
986
+ PyModule_AddObject (object, QStringToPythonCharPointer (name ), _p->wrapQObject (qObject));
987
987
} else if (PyDict_Check (object)) {
988
- PyDict_SetItemString (object, name. toLatin1 (). data ( ), _p->wrapQObject (qObject));
988
+ PyDict_SetItemString (object, QStringToPythonCharPointer (name ), _p->wrapQObject (qObject));
989
989
} else {
990
- PyObject_SetAttrString (object, name. toLatin1 (). data ( ), _p->wrapQObject (qObject));
990
+ PyObject_SetAttrString (object, QStringToPythonCharPointer (name ), _p->wrapQObject (qObject));
991
991
}
992
992
}
993
993
994
994
void PythonQt::addVariable (PyObject* object, const QString& name, const QVariant& v)
995
995
{
996
996
if (PyModule_Check (object)) {
997
- PyModule_AddObject (object, name. toLatin1 (). data ( ), PythonQtConv::QVariantToPyObject (v));
997
+ PyModule_AddObject (object, QStringToPythonCharPointer (name ), PythonQtConv::QVariantToPyObject (v));
998
998
} else if (PyDict_Check (object)) {
999
- PyDict_SetItemString (object, name. toLatin1 (). data ( ), PythonQtConv::QVariantToPyObject (v));
999
+ PyDict_SetItemString (object, QStringToPythonCharPointer (name ), PythonQtConv::QVariantToPyObject (v));
1000
1000
} else {
1001
- PyObject_SetAttrString (object, name. toLatin1 (). data ( ), PythonQtConv::QVariantToPyObject (v));
1001
+ PyObject_SetAttrString (object, QStringToPythonCharPointer (name ), PythonQtConv::QVariantToPyObject (v));
1002
1002
}
1003
1003
}
1004
1004
1005
1005
void PythonQt::removeVariable (PyObject* object, const QString& name)
1006
1006
{
1007
1007
if (PyDict_Check (object)) {
1008
- PyDict_DelItemString (object, name. toLatin1 (). data ( ));
1008
+ PyDict_DelItemString (object, QStringToPythonCharPointer (name ));
1009
1009
} else {
1010
- PyObject_DelAttrString (object, name. toLatin1 (). data ( ));
1010
+ PyObject_DelAttrString (object, QStringToPythonCharPointer (name ));
1011
1011
}
1012
1012
}
1013
1013
@@ -1033,7 +1033,7 @@ QStringList PythonQt::introspection(PyObject* module, const QString& objectname,
1033
1033
if (!object && type == CallOverloads) {
1034
1034
PyObject* dict = lookupObject (module , " __builtins__" );
1035
1035
if (dict) {
1036
- object = PyDict_GetItemString (dict, objectname. toLatin1 (). constData ( ));
1036
+ object = PyDict_GetItemString (dict, QStringToPythonCharPointer (objectname ));
1037
1037
}
1038
1038
}
1039
1039
}
@@ -1089,7 +1089,14 @@ QStringList PythonQt::introspectObject(PyObject* object, ObjectType type)
1089
1089
keys = PyDict_Keys (object);
1090
1090
isDict = true ;
1091
1091
} else {
1092
+ #if defined(MEVISLAB) && !defined(PY3K)
1093
+ int oldPy3kWarningFlag = Py_Py3kWarningFlag;
1094
+ Py_Py3kWarningFlag = 0 ; // temporarily disable Python 3 warnings
1092
1095
keys = PyObject_Dir (object);
1096
+ Py_Py3kWarningFlag = oldPy3kWarningFlag;
1097
+ #else
1098
+ keys = PyObject_Dir (object);
1099
+ #endif
1093
1100
}
1094
1101
if (keys) {
1095
1102
int count = PyList_Size (keys);
@@ -1170,15 +1177,15 @@ PyObject* PythonQt::getObjectByType(const QString& typeName)
1170
1177
QString moduleName = tmp.join (" ." );
1171
1178
1172
1179
PyObject* object = NULL ;
1173
- PyObject* moduleObject = PyDict_GetItemString (modules, moduleName. toLatin1 (). constData ( ));
1180
+ PyObject* moduleObject = PyDict_GetItemString (modules, QStringToPythonCharPointer (moduleName ));
1174
1181
if (moduleObject) {
1175
- object = PyObject_GetAttrString (moduleObject, simpleTypeName. toLatin1 (). constData ( ));
1182
+ object = PyObject_GetAttrString (moduleObject, QStringToPythonCharPointer (simpleTypeName ));
1176
1183
}
1177
1184
1178
1185
if (!object) {
1179
1186
moduleObject = PyDict_GetItemString (modules, " __builtin__" );
1180
1187
if (moduleObject) {
1181
- object = PyObject_GetAttrString (moduleObject, simpleTypeName. toLatin1 (). constData ( ));
1188
+ object = PyObject_GetAttrString (moduleObject, QStringToPythonCharPointer (simpleTypeName ));
1182
1189
}
1183
1190
}
1184
1191
@@ -1202,7 +1209,7 @@ QStringList PythonQt::introspectType(const QString& typeName, ObjectType type)
1202
1209
}
1203
1210
PyObject* typeObject = getObjectByType (typeName);
1204
1211
if (typeObject) {
1205
- object = PyObject_GetAttrString (typeObject, memberName. toLatin1 (). constData ( ));
1212
+ object = PyObject_GetAttrString (typeObject, QStringToPythonCharPointer (memberName ));
1206
1213
}
1207
1214
}
1208
1215
if (object) {
@@ -1272,7 +1279,7 @@ PyObject* PythonQt::callAndReturnPyObject(PyObject* callable, const QVariantList
1272
1279
it.next ();
1273
1280
PyObject* arg = PythonQtConv::QVariantToPyObject (it.value ());
1274
1281
if (arg) {
1275
- PyDict_SetItemString (pkwargs, it.key (). toLatin1 (). constData ( ), arg);
1282
+ PyDict_SetItemString (pkwargs, QStringToPythonCharPointer ( it.key ()), arg);
1276
1283
} else {
1277
1284
err = true ;
1278
1285
break ;
@@ -1434,7 +1441,7 @@ void PythonQtPrivate::addDecorators(QObject* o, int decoTypes)
1434
1441
void PythonQtPrivate::registerQObjectClassNames (const QStringList& names)
1435
1442
{
1436
1443
Q_FOREACH (QString name, names) {
1437
- _knownQObjectClassNames.insert (name.toLatin1 (), true );
1444
+ _knownQObjectClassNames.insert (name.toUtf8 (), true );
1438
1445
}
1439
1446
}
1440
1447
@@ -1602,7 +1609,7 @@ void PythonQt::setModuleImportPath(PyObject* module, const QStringList& paths)
1602
1609
void PythonQt::stdOutRedirectCB (const QString& str)
1603
1610
{
1604
1611
if (!PythonQt::self ()) {
1605
- std::cout << str. toLatin1 (). data ( ) << std::endl;
1612
+ std::cout << QStringToPythonConstCharPointer (str ) << std::endl;
1606
1613
return ;
1607
1614
}
1608
1615
Q_EMIT PythonQt::self ()->pythonStdOut (str);
@@ -1611,7 +1618,7 @@ void PythonQt::stdOutRedirectCB(const QString& str)
1611
1618
void PythonQt::stdErrRedirectCB (const QString& str)
1612
1619
{
1613
1620
if (!PythonQt::self ()) {
1614
- std::cerr << str. toLatin1 (). data ( ) << std::endl;
1621
+ std::cerr << QStringToPythonConstCharPointer (str ) << std::endl;
1615
1622
return ;
1616
1623
}
1617
1624
Q_EMIT PythonQt::self ()->pythonStdErr (str);
@@ -1727,9 +1734,9 @@ QString PythonQt::getReturnTypeOfWrappedMethodHelper(const PythonQtObjectPtr& va
1727
1734
{
1728
1735
PythonQtObjectPtr methodObject;
1729
1736
if (PyDict_Check (variableObject)) {
1730
- methodObject = PyDict_GetItemString (variableObject, methodName. toLatin1 (). constData ( ));
1737
+ methodObject = PyDict_GetItemString (variableObject, QStringToPythonConstCharPointer (methodName ));
1731
1738
} else {
1732
- methodObject.setNewRef (PyObject_GetAttrString (variableObject, methodName. toLatin1 (). constData ( )));
1739
+ methodObject.setNewRef (PyObject_GetAttrString (variableObject, QStringToPythonConstCharPointer (methodName )));
1733
1740
}
1734
1741
if (methodObject.isNull ()) {
1735
1742
return " " ;
@@ -1754,7 +1761,7 @@ QString PythonQt::getReturnTypeOfWrappedMethodHelper(const PythonQtObjectPtr& va
1754
1761
// if the type is a known class info, then create the full type name, i.e. include the
1755
1762
// module name. For example, the slot may return a QDate, then this looks up the
1756
1763
// name _PythonQt.QtCore.QDate.
1757
- PythonQtClassInfo* typeInfo = _p->_knownClassInfos .value (type. toLatin1 (). constData ( ));
1764
+ PythonQtClassInfo* typeInfo = _p->_knownClassInfos .value (QStringToPythonConstCharPointer (type ));
1758
1765
if (typeInfo && typeInfo->pythonQtClassWrapper ()) {
1759
1766
PyObject* s = PyObject_GetAttrString (typeInfo->pythonQtClassWrapper (), " __module__" );
1760
1767
Q_ASSERT (PyString_Check (s));
@@ -1851,7 +1858,7 @@ PyObject* PythonQtPrivate::packageByName(const char* name)
1851
1858
void PythonQtPrivate::handleVirtualOverloadReturnError (const char * signature, const PythonQtMethodInfo* methodInfo, PyObject* result)
1852
1859
{
1853
1860
QString error = " Return value '" + PythonQtConv::PyObjGetString (result) + " ' can not be converted to expected C++ type '" + methodInfo->parameters ().at (0 ).name + " ' as return value of virtual method " + signature;
1854
- PyErr_SetString (PyExc_AttributeError, error. toLatin1 (). data ( ));
1861
+ PyErr_SetString (PyExc_AttributeError, QStringToPythonCharPointer (error ));
1855
1862
PythonQt::self ()->handleError ();
1856
1863
}
1857
1864
@@ -1861,7 +1868,7 @@ PyObject* PythonQt::helpCalled(PythonQtClassInfo* info)
1861
1868
Q_EMIT pythonHelpRequest (QByteArray (info->className ()));
1862
1869
return Py_BuildValue (" " );
1863
1870
} else {
1864
- return PyString_FromString (info->help (). toLatin1 (). data ( ));
1871
+ return PyString_FromString (QStringToPythonCharPointer ( info->help ()));
1865
1872
}
1866
1873
}
1867
1874
@@ -1911,7 +1918,7 @@ PythonQtObjectPtr PythonQtPrivate::createModule(const QString& name, PyObject* p
1911
1918
PythonQtObjectPtr result;
1912
1919
PythonQt::self ()->clearError ();
1913
1920
if (pycode) {
1914
- result.setNewRef (PyImport_ExecCodeModule (( char *) name. toLatin1 (). data ( ), pycode));
1921
+ result.setNewRef (PyImport_ExecCodeModule (QStringToPythonCharPointer ( name), pycode));
1915
1922
} else {
1916
1923
PythonQt::self ()->handleError ();
1917
1924
}
@@ -2306,7 +2313,7 @@ PyObject* PythonQtPrivate::wrapMemoryAsBuffer( const void* data, Py_ssize_t size
2306
2313
PyObject* PythonQtPrivate::wrapMemoryAsBuffer ( void * data, Py_ssize_t size )
2307
2314
{
2308
2315
#ifdef PY3K
2309
- return PyMemoryView_FromMemory ((char *)data, size, PyBUF_READ | PyBUF_WRITE);
2316
+ return PyMemoryView_FromMemory ((char *)data, size, PyBUF_WRITE);
2310
2317
#else
2311
2318
return PyBuffer_FromReadWriteMemory ((char *)data, size);
2312
2319
#endif
0 commit comments