Exception: cannot return std::string from Unicode object

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Exception: cannot return std::string from Unicode object

Post by looo »

what is causing this exception? Everytime this object (https://github.com/hiaselhans/OpenGlide ... _glider.py) is recalculated it throw the exception:

<unknown exception traceback><type 'exceptions.TypeError'>: cannot return std::string from Unicode object

any ideas?
User avatar
shoogen
Veteran
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Re: Exception: cannot return std::string from Unicode object

Post by shoogen »

My first educated guess would be that .getIcon in the view provider proxy returns a unicode object (for the path). If this i the case, you can try to remove the whole function, as a workaround.
(In my version FreeCAD.getHomePath() returns a unicode object. :( )
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: Exception: cannot return std::string from Unicode object

Post by looo »

perfect, thanks. With str(...) it works.

OS: Ubuntu 14.04.1 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.15.4531 (Git)
Branch: master
Hash: 8628a6e0e0ef9223bff722b1278e5211039ae1b7
Python version: 2.7.6
Qt version: 4.8.6
Coin version: 4.0.0a
User avatar
shoogen
Veteran
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Re: Exception: cannot return std::string from Unicode object

Post by shoogen »

Code: Select all

diff --git a/src/Gui/ViewProviderPythonFeature.cpp b/src/Gui/ViewProviderPythonF
index f5f869e..3632b37 100644
--- a/src/Gui/ViewProviderPythonFeature.cpp
+++ b/src/Gui/ViewProviderPythonFeature.cpp
@@ -247,10 +247,10 @@ QIcon ViewProviderPythonFeatureImp::getIcon() const
                 Py::Callable method(vp.getAttr(std::string("getIcon")));
                 Py::Tuple args;
                 Py::String str(method.apply(args));
-                std::string content = str.as_std_string();
+                std::string content = str.as_std_string("utf-8");
                 QPixmap icon;
                 // Check if the passed string is a filename, otherwise treat as
-                QFileInfo fi(QString::fromAscii(content.c_str()));
+                QFileInfo fi(QString::fromUtf8(content.c_str()));
                 if (fi.isFile() && fi.exists()) {
                     icon.load(fi.absoluteFilePath());
                 } else {
Post Reply