Menu

UTF8 support for some functions

Anonymous
2010-08-11
2013-04-06
  • Anonymous

    Anonymous - 2010-08-11

    PythonQtScriptingConsole (183): replace with
        PyCompilerFlags pyCFlags;
        pyCFlags.cf_flags = PyCF_SOURCE_IS_UTF8;
        p.setNewRef(PyRun_StringFlags(code.toUtf8(), Py_single_input, dict, dict, &pyCFlags));

    PythonQt.cpp (605) replace with:
        PyCompilerFlags pyCFlags;
        pyCFlags.cf_flags = PyCF_SOURCE_IS_UTF8;
        p.setNewRef(PyRun_StringFlags(script.toUtf8(), start, dict, dict, &pyCFlags));

    After that you can write something like this:
    push1.text = 'yourlanguage'

     
  • herczeg3725

    herczeg3725 - 2011-06-06

    Thanks for the hint!
    Why is this flag not default?

     
  • Sergey

    Sergey - 2011-07-07

    Hello!
    If the script is executed using the evalFile, for example,

        ...
        console = new PythonQtScriptingConsole (0, context);
        ...
        PythonQt:: self () -> getMainModule (). EvalFile (": example.py");
        console-> appendCommandPrompt ();
        console-> show ();
    

    then everything is fine with the encoding of the string. The script is simple:

        val = 'Русский'
        print val
    

    If those statements are executed in PythonQtScriptingConsole, the output is unreadable, like this: Р СѓСЃСЃРєРёР№
    In what may be the problem?

    Yours faithfully,
    Sergey.

     
  • Sergey

    Sergey - 2011-11-02

    To enable utf-8 support is sufficient to make the substitution:
    PythonQtScriptingConsole.cpp (183): replace with
        p.setNewRef(PyRun_String(code.toAscii().data(), Py_single_input, dict, dict));

    PythonQt.cpp (611 - из репозитория) replace with:
        p.setNewRef(PyRun_String(script.toAscii().data(), start, dict, dict));

    Line numbers are indicated for the code from the repository (199 revision).
    It has no problems in the console, too (see above).

     

Log in to post a comment.