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. [PyQt5] QTableWidget Input crash with wchar_t (specifically, Korean characters)
QtWS25 Last Chance

[PyQt5] QTableWidget Input crash with wchar_t (specifically, Korean characters)

Scheduled Pinned Locked Moved Unsolved Qt for Python
11 Posts 7 Posters 1.1k 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.
  • C Offline
    C Offline
    chan1123
    wrote on last edited by chan1123
    #1

    Hi. I'm developing my application with PyQt5.
    I'm using QTableWidget, but when I try to insert Korean characters, it crashes.

    I will describe what's possible and not possible.
    After executing my program, I can click one cell on the QTableWidget.
    And then, If I try to put a korean character with the changed input mode with convert key,
    It crashes.

    However, If I double click one cell on the QTableWidget, the cell edit is activated. And
    I can see the text edit cursor. When it's in the situation, I can write korean characters without crash.

    But, When I just use English, There is no problem like above.

    Is there any way to solve this problem If I click one cell and try to put korean characters?

    Thanks in advance.

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

      Hi and welcome to devnet,

      Please provide a minimal example that reproduces your situation as well as a source for Korean input.

      By the way:

      • What version of PyQt5 are your using ?
      • On what OS ?
      • What python version ?

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

      C 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Please provide a minimal example that reproduces your situation as well as a source for Korean input.

        By the way:

        • What version of PyQt5 are your using ?
        • On what OS ?
        • What python version ?
        C Offline
        C Offline
        chan1123
        wrote on last edited by chan1123
        #3

        Hi @SGaist .

        • PyQt5 : 5.14.1
        • Windows 10 1909
        • Python 3.7 (32bit)

        This is the minimal example that reproduces my situation.
        and I noticed that the crash does not happen when I deleted setCellWidget().

        I'm not sure you can have another country keyboard input.
        You need your korean keyboard input to reproduce this crash.

        So to reproduce this situation.

        1. Get the Korean keyboard input
        2. Execute this program
        3. Convert input mode into Korean Input
        4. Click one cell once
        5. put the keyboard input
        6. crash

        As I already said, the program does not crash with English.

        import sys
        from PyQt5.QtCore import *
        from PyQt5.QtGui import *
        from PyQt5.QtWidgets import *
        
        screenWidth = 800
        screenHeight = 600
        
        def testCallback():
            print("cell changed")
        
        def main():
            # App 초기화
            App = QApplication(sys.argv)
        
            # Window 초기화
            Window = QMainWindow()
            myDesktop = QApplication.desktop()
            rect = myDesktop.screenGeometry()
            Window.setGeometry(rect.width() / 2 - screenWidth / 2, rect.height() / 2 - screenHeight / 2, screenWidth, screenHeight);
            
            Widget = QWidget()
            myLayout = QVBoxLayout(Widget)
            myLabel = QLabel("blah")
            myLayout.addWidget(myLabel)
            myTable = QTableWidget(10, 3)
            
            myTable.setItem(0, 0, QTableWidgetItem(""))
            myTable.setItem(0, 1, QTableWidgetItem(""))
            myTable.setHorizontalHeaderLabels(("테스트1", "테스트2", "기능"))
            myTable.cellChanged.connect(testCallback)
            myLayout.addWidget(myTable)
            myTable.setCellWidget(0, 2, QLabel("hallo"))
        
            Window.setCentralWidget(Widget)
            Window.show()
        
            App.exec_()
        
        if __name__ == "__main__":
            main()
        

        I found the same issue on the Stackoverflow : https://stackoverflow.com/questions/54923039/pyqt5-with-qtablewidget-program-crashes-without-any-exception

        I guess there is some error code on the QTableWidget implementation when handling with UTF-8 input, with the CellWidget added.

        1 Reply Last reply
        0
        • eyllanescE Offline
          eyllanescE Offline
          eyllanesc
          wrote on last edited by eyllanesc
          #4

          @chan1123 Your code has an error: The callback that is expected to be callable (function, method, etc.) but instead you pass a string:

          class AddButton(QPushButton):
              def __init__(self, callback, rowIndex):
                  super(QPushButton, self).__init__("Add")
                  self.rowIndex = rowIndex
                  self.clicked.connect(lambda: callback(self))
          
          myTable.setCellWidget(0, 2, AddButton("", 0))
          

          Where:

          callback = ""
          rowIndex = 0
          

          I recommend you to run your code in the console/terminal/CMD since many IDEs do not handle Qt errors correctly.

          If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

          C 1 Reply Last reply
          0
          • eyllanescE eyllanesc

            @chan1123 Your code has an error: The callback that is expected to be callable (function, method, etc.) but instead you pass a string:

            class AddButton(QPushButton):
                def __init__(self, callback, rowIndex):
                    super(QPushButton, self).__init__("Add")
                    self.rowIndex = rowIndex
                    self.clicked.connect(lambda: callback(self))
            
            myTable.setCellWidget(0, 2, AddButton("", 0))
            

            Where:

            callback = ""
            rowIndex = 0
            

            I recommend you to run your code in the console/terminal/CMD since many IDEs do not handle Qt errors correctly.

            C Offline
            C Offline
            chan1123
            wrote on last edited by chan1123
            #5

            @eyllanesc Okay. I see.
            But, That's not the point in this issue.

            I changed the code like this. It still crashes.

            import sys
            from PyQt5.QtCore import *
            from PyQt5.QtGui import *
            from PyQt5.QtWidgets import *
            
            screenWidth = 800
            screenHeight = 600
            
            def testCallback():
                print("cell changed")
            
            def main():
                # App 초기화
                App = QApplication(sys.argv)
            
                # Window 초기화
                Window = QMainWindow()
                myDesktop = QApplication.desktop()
                rect = myDesktop.screenGeometry()
                Window.setGeometry(rect.width() / 2 - screenWidth / 2, rect.height() / 2 - screenHeight / 2, screenWidth, screenHeight);
                
                Widget = QWidget()
                myLayout = QVBoxLayout(Widget)
                myLabel = QLabel("blah")
                myLayout.addWidget(myLabel)
                myTable = QTableWidget(10, 3)
                
                myTable.setItem(0, 0, QTableWidgetItem(""))
                myTable.setItem(0, 1, QTableWidgetItem(""))
                myTable.setHorizontalHeaderLabels(("테스트1", "테스트2", "기능"))
                myTable.cellChanged.connect(testCallback)
                myLayout.addWidget(myTable)
                myTable.setCellWidget(0, 2, QLabel("hallo"))
            
                Window.setCentralWidget(Widget)
                Window.show()
            
                App.exec_()
            
            if __name__ == "__main__":
                main()
            

            And I also executed the program on Windows Command line terminal.
            and it does not output anything when it crahses.

            1 Reply Last reply
            0
            • eyllanescE Offline
              eyllanescE Offline
              eyllanesc
              wrote on last edited by eyllanesc
              #6

              @chan1123 In Linux with PyQt5 5.14.1 and python 3.8 I don't see that problem. You could indicate the versions of the libraries in your environment.

              If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

              C 1 Reply Last reply
              0
              • eyllanescE eyllanesc

                @chan1123 In Linux with PyQt5 5.14.1 and python 3.8 I don't see that problem. You could indicate the versions of the libraries in your environment.

                C Offline
                C Offline
                chan1123
                wrote on last edited by
                #7

                @eyllanesc
                What does "the versions of the libraries" mean?
                My environment is

                • PyQt5 : 5.14.1
                • Windows 10 1909
                • Python 3.7 (32bit)

                you are on the Linux, and I'm on the Windows

                And Did you do my reproduction order? :

                1. Get the Korean keyboard input
                2. Execute this program
                3. Convert input mode into Korean Input
                4. Click one cell once
                5. put the keyboard input
                6. crash
                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  chan1123
                  wrote on last edited by
                  #8

                  @Denni-0
                  Hi. I already wrote the MRE in the previous comment.
                  Please, look at the previous comments carefully.

                  And Can you give me a link where there is the compatibility issues document?

                  1 Reply Last reply
                  1
                  • J Offline
                    J Offline
                    John1014
                    wrote on last edited by
                    #9

                    I had the same problem when typing Chinese character in QTableWidget if QTableWidget contain a widget in a cell

                    1 Reply Last reply
                    0
                    • X Offline
                      X Offline
                      XiaoTuDui
                      wrote on last edited by
                      #10

                      I had the same problem when typing Chinese character in QTableWidget if QTableWidget contain a widget in a cell

                      1 Reply Last reply
                      0
                      • C chan1123

                        Hi. I'm developing my application with PyQt5.
                        I'm using QTableWidget, but when I try to insert Korean characters, it crashes.

                        I will describe what's possible and not possible.
                        After executing my program, I can click one cell on the QTableWidget.
                        And then, If I try to put a korean character with the changed input mode with convert key,
                        It crashes.

                        However, If I double click one cell on the QTableWidget, the cell edit is activated. And
                        I can see the text edit cursor. When it's in the situation, I can write korean characters without crash.

                        But, When I just use English, There is no problem like above.

                        Is there any way to solve this problem If I click one cell and try to put korean characters?

                        Thanks in advance.

                        M Offline
                        M Offline
                        minor code
                        wrote on last edited by
                        #11

                        HELP!!!!
                        same issue : https://forum.qt.io/topic/141477/qtablewidget-setcellwidget-input-crash-bug

                        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