Skip to content

Commit b7fea57

Browse files
committed
fix python error on startup on windows
1 parent 5129527 commit b7fea57

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/python/qgspythonutilsimpl.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,13 @@ QString QgsPythonUtilsImpl::getTraceback()
399399
TRACEBACK_FETCH_ERROR( "getvalue() failed." );
400400

401401
/* And it should be a string all ready to go - duplicate it. */
402-
if ( !PyUnicode_Check( obResult ) )
402+
if ( !
403+
#ifdef PYTHON2
404+
PyString_Check( obResult )
405+
#else
406+
PyUnicode_Check( obResult )
407+
#endif
408+
)
403409
TRACEBACK_FETCH_ERROR( "getvalue() did not return a string" );
404410

405411
result = PYOBJ2QSTRING( obResult );
@@ -506,7 +512,16 @@ QString QgsPythonUtilsImpl::PyObjectToQString( PyObject* obj )
506512
// check whether the object is already a unicode string
507513
if ( PyUnicode_Check( obj ) )
508514
{
515+
#ifdef PYTHON2
516+
PyObject* utf8 = PyUnicode_AsUTF8String( obj );
517+
if ( utf8 )
518+
result = QString::fromUtf8( PyString_AS_STRING( utf8 ) );
519+
else
520+
result = "(qgis error)";
521+
Py_XDECREF( utf8 );
522+
#else
509523
result = PYOBJ2QSTRING( obj );
524+
#endif
510525
return result;
511526
}
512527

0 commit comments

Comments
 (0)