[Tutor] Convert Qstring to string in windows

Danny Yoo dyoo at hashcollision.org
Thu Oct 16 20:14:22 CEST 2014


On Thu, Oct 16, 2014 at 8:21 AM, C at rlos <cmferras at estudiantes.uci.cu> wrote:
>
> I have been tryed to convert a Qstring text to string on python, in linux
> that work fine but in windows when qstring contine á,é,í,ó,ú the converted
> text is not correct, contine extranger characters,
> this qstring text is an url from qdialogtext.
>
> in linux i do for this way:
> pythonstringtext=qstringtext.text().toUtf8.data()
> and it return a python string correctly.


Hi Carlos,

This seems like a question that's very specific to Qt: you may want to
ask on a Qt-Python mailing list.  Tutor is intended for beginner
programmers, and the question you're asking seems a bit specialized
for the intended audience.


In absence of this information, I have to make a few guesses.  My best
guesses so far are that you're working with Qt, which provides its own
Unicode string class:

    http://qt-project.org/doc/qt-4.8/qstring.html

Are you using PyQt 4 or PyQt 5, or something else entirely?  Are you
using Python 2 or Python 3?

According to the PyQt5 documentation, it automatically handles the
string conversion:

    http://pyqt.sourceforge.net/Docs/PyQt5/gotchas.html#python-strings-qt-strings-and-unicode

and according to the PyQt 4 documentation, it also handles the
conversion automatically for you:

    http://pyqt.sourceforge.net/Docs/PyQt4/python_v3.html#qstring

and because the mapping is done by the library, you should not have to
be doing anything on your own end to convert Qstrings to Python
strings.


Yeah, I am not sure what you are doing yet, because the documentation
says that it handles conversions for you.  The fact that you're doing
this manually suggests that you might be doing something unusual.  We
need more information.  But I think you may get better help on a
Qt-specific mailing list; I suspect very few of us here have Qt
experience.


More information about the Tutor mailing list