Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. [SOLVED] PySide strings returned from widgets have extra blank bytes between the letters

[SOLVED] PySide strings returned from widgets have extra blank bytes between the letters

Scheduled Pinned Locked Moved Language Bindings
6 Posts 2 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dgollas
    wrote on last edited by
    #1

    Hi,
    I built pyside using the buildscripts on CentOS 6.5 and Qt 4.8 (installed using these repos http://www.qtcentre.org/threads/56495-How-to-install-4-8-on-CentOS-6) on a virtual environment using Python 2.7

    I tested an application that works perfectly fine on Windows and OSX and found that whenever I printed a string from a widget (ie. comboBox.currentText() where comboBox is a QComboBox) I was missing half the string.

    Checking the length of the returned object I found that it had the correct length, but uppon further inspection I realized it had an extra blank byte between each letter. For example, a QLineEdit with the text "hello" would only print "hel".

    Printing the string as hex bytes using:

    @print ":".join(['%0X' % ord(b) for b in myString])@

    resulted in something like 68:0:65:0:6C, where indeed there is a 0 byte between each character.

    The GUI is built using pyside-uic from ui files created in the Creator.

    This sounds like I'm getting two byte unicode characters, but why am I only getting half the bytes?

    Am I missing something that needs to be configured at the app level?

    Please help and thanks for any info in advance!

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dgollas
      wrote on last edited by
      #2

      Here is a trivial example that prints text from a QLineEdit.
      The QLineEdit text is set from a regular python string.
      When printing the original text and the text read from QLineEdit.text() they print out different things.

      @
      import sys
      from PySide import QtGui
      from PySide import QtCore

      edit=None
      myText=str("hello how are you")

      def printSomething():

      textFromQt=edit.text()
      print "\n---%s: %i---"%(textFromQt,len(textFromQt))
      for l in textFromQt:
      print '%s : %0X' % (l, ord(l) )

      print "\n\n---%s: %i---"%(myText,len(myText))
      for l in myText:
      print '%s : %0X' % (l, ord(l) )

      if name == "main":
      app = QtGui.QApplication(sys.argv)
      wnd=QtGui.QDialog()
      layout= QtGui.QVBoxLayout(wnd)
      btn=QtGui.QPushButton("push", wnd)
      edit=QtGui.QLineEdit(myText)
      layout.addWidget(edit)
      layout.addWidget(btn)

      btn.clicked.connect(printSomething)
      wnd.show()
      sys.exit(app.exec_())
      @

      And the output when pushing the button is:

      @
      ---hello how: 17---
      h : 68
      : 0
      e : 65
      : 0
      l : 6C
      : 0
      l : 6C
      : 0
      o : 6F
      : 0
      : 20
      : 0
      h : 68
      : 0
      o : 6F
      : 0
      w : 77

      ---hello how are you: 17---
      h : 68
      e : 65
      l : 6C
      l : 6C
      o : 6F
      : 20
      h : 68
      o : 6F
      w : 77
      : 20
      a : 61
      r : 72
      e : 65
      : 20
      y : 79
      o : 6F
      u : 75
      @

      Thanks for any help!

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        Since it might be low level problem, you should also post your question on the pyside mailing list.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dgollas
          wrote on last edited by
          #4

          Ok, I found the solution.

          CentOS comes with Python 2.6 and I had created my virtual environment with Python 2.7 compiled from source.

          I recompiled Python 2.7 adding --enable-unicode=ucs4 when configuring the build. The default is to compile with --enable-unicode=ucs2

          so in the end I compiled like this:

          @
          ./configure --prefix /usr/local --enable-shared --enable-unicode=ucs4
          make
          make altinstall
          @

          I recreated my virtualenv with the newly compiled python and everything works as it should!

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            That might be something to talk about with the pyside devs

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dgollas
              wrote on last edited by
              #6

              [quote author="SGaist" date="1406317872"]That might be something to talk about with the pyside devs[/quote]

              I'll share my findings with the list. Cheers!

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved