Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Return type of QLineEdit:text
Forum Updated to NodeBB v4.3 + New Features

Return type of QLineEdit:text

Scheduled Pinned Locked Moved Solved Qt for Python
7 Posts 3 Posters 1.1k Views 2 Watching
  • 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.
  • B Offline
    B Offline
    buhtz
    wrote on last edited by
    #1

    I wonder what QLineEdit.text returns?

    https://doc.qt.io/qt-6/qlineedit.html#text-prop

    It seems to be a QString. But based on that Issue it sometimes returns a str instance.

    How can I know?

    Was there a change between Qt versions?

    JonBJ 1 Reply Last reply
    0
    • B buhtz

      I wonder what QLineEdit.text returns?

      https://doc.qt.io/qt-6/qlineedit.html#text-prop

      It seems to be a QString. But based on that Issue it sometimes returns a str instance.

      How can I know?

      Was there a change between Qt versions?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @buhtz
      It has always been the case that PyQt and/or PySide convert freely between QString and Python str for you. (PyQt at least does not have a QString type, IIRC.) Same with some other types....

      B 1 Reply Last reply
      1
      • JonBJ JonB

        @buhtz
        It has always been the case that PyQt and/or PySide convert freely between QString and Python str for you. (PyQt at least does not have a QString type, IIRC.) Same with some other types....

        B Offline
        B Offline
        buhtz
        wrote on last edited by
        #3

        @JonB said in Return type of QLineEdit:text:

        It has always been the case that PyQt and/or PySide convert freely between QString and Python str for you.

        Mhm... This confuses me much more. :D

        In the Issue I was linking there is this line of Python code

        diff_cmd = str( self.edit_command.text().toUtf8() )
        

        The reported error was "str doesn't have toUtf8()". The Issue was reported in 2018 and never fixed. But the application (incl. this toUtf8()) was released more then once since 2018 and today.

        I can't explain that to myself. Maybe it is about a new Qt or PyQt version?

        I am scared to break the code. And without knowing much more about it I have to do some real tests using older Linux distros if this would break anything.

        B JonBJ 2 Replies Last reply
        0
        • B buhtz

          @JonB said in Return type of QLineEdit:text:

          It has always been the case that PyQt and/or PySide convert freely between QString and Python str for you.

          Mhm... This confuses me much more. :D

          In the Issue I was linking there is this line of Python code

          diff_cmd = str( self.edit_command.text().toUtf8() )
          

          The reported error was "str doesn't have toUtf8()". The Issue was reported in 2018 and never fixed. But the application (incl. this toUtf8()) was released more then once since 2018 and today.

          I can't explain that to myself. Maybe it is about a new Qt or PyQt version?

          I am scared to break the code. And without knowing much more about it I have to do some real tests using older Linux distros if this would break anything.

          B Offline
          B Offline
          buhtz
          wrote on last edited by
          #4

          So please don't waste more of your time here.

          After some more research I assume that the dialog using this "buggy" code was rarely or never used by the users (for years). That is why the bug could live in the released code.

          1 Reply Last reply
          0
          • B buhtz

            @JonB said in Return type of QLineEdit:text:

            It has always been the case that PyQt and/or PySide convert freely between QString and Python str for you.

            Mhm... This confuses me much more. :D

            In the Issue I was linking there is this line of Python code

            diff_cmd = str( self.edit_command.text().toUtf8() )
            

            The reported error was "str doesn't have toUtf8()". The Issue was reported in 2018 and never fixed. But the application (incl. this toUtf8()) was released more then once since 2018 and today.

            I can't explain that to myself. Maybe it is about a new Qt or PyQt version?

            I am scared to break the code. And without knowing much more about it I have to do some real tests using older Linux distros if this would break anything.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @buhtz
            Don't quote me on this, but Python has encode('utf-8'), e.g. https://www.programiz.com/python-programming/methods/string/encode. Maybe you could do it that side? I have never understood encoding, despite asking many times and people explaining I just find it confusing! You may need an encoding expert who also does Python, maybe @SGaist will see this, if he doesn't mind he may be able to comment.

            B 1 Reply Last reply
            0
            • JonBJ JonB

              @buhtz
              Don't quote me on this, but Python has encode('utf-8'), e.g. https://www.programiz.com/python-programming/methods/string/encode. Maybe you could do it that side? I have never understood encoding, despite asking many times and people explaining I just find it confusing! You may need an encoding expert who also does Python, maybe @SGaist will see this, if he doesn't mind he may be able to comment.

              B Offline
              B Offline
              buhtz
              wrote on last edited by
              #6

              @JonB Thanks for the hint. But since Python 3 there is no real need for encoding anymore. In most cases everything is utf-8 by default. But of course there are edge cases (e.g. default encoding when opening files on windows).

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

                Hi,

                You likely have triggered something that either was never reported or a feature that was rarely used/triggered that it went unnoticed.

                From memory, even in the PyQt4 time, the bindings would not provide QString not QByteArray. My guess is that the code was translated a bit too literally from a C++ example.

                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
                1

                • Login

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