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. Combobox query with text file
Forum Updated to NodeBB v4.3 + New Features

Combobox query with text file

Scheduled Pinned Locked Moved Solved Qt for Python
14 Posts 3 Posters 1.3k Views 1 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.
  • J Offline
    J Offline
    Julsenn
    wrote on last edited by
    #1

    Hello, if I try to match the text from the combobox with the text from my text file, the program crashes, someone can help me ? Thanks.

        def four(self):
            with open("Slot1.txt", "r") as f:
                file_text1 = f.readline()
                combotxt = comboBox.currentText()
    
                file_text1 == combotxt
                print("true")
    
    JonBJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What is the crash back trace ?

      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
      • J Offline
        J Offline
        Julsenn
        wrote on last edited by
        #3

        hi,
        Python has stopped working

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

          That's not a backtrace.

          You should also provide a minimal example that triggers that crash.

          Also, what version of Python are you using ?
          Are you using PyQt5 or PySide2 ?
          Which version ?

          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
          • J Offline
            J Offline
            Julsenn
            wrote on last edited by
            #5

            As soon as I call up the def with my button, the program crashes and I don't get an error message.
            PyQt5
            Version 3.7.4

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

              Where is Slot1.txt located ?
              What version of PyQt5 ?
              What OS are you running ?

              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
              • J Offline
                J Offline
                Julsenn
                wrote on last edited by
                #7

                in the same folder as the py
                windows 5.14.1

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  Julsenn
                  wrote on last edited by
                  #8

                  in the txt file just stands "hello" und genauso in der combobox.
                  I want to ask if the texts are the same.

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

                    *same in the combobox

                    1 Reply Last reply
                    0
                    • J Julsenn

                      Hello, if I try to match the text from the combobox with the text from my text file, the program crashes, someone can help me ? Thanks.

                          def four(self):
                              with open("Slot1.txt", "r") as f:
                                  file_text1 = f.readline()
                                  combotxt = comboBox.currentText()
                      
                                  file_text1 == combotxt
                                  print("true")
                      
                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #10

                      @Julsenn
                      Python does not usually "crash". If the code you show really crashes, the most likely would be if comboBox is not set to a QComboBox, but even then I'd be surprised.

                      If the file cannot be opened for read, the open() will raise an exception. Again this should not cause a "crash", but I don't know what your code does if an exception is raised.

                                  file_text1 == combotxt
                                  print("true")
                      

                      This always prints true; the first line does nothing. I'm sure you know how to write an if statement correctly in Python.

                      If you want to find out how far your code gets before "crashing", and you're not using a debugger, put a print(0) before the first statement, print(1) before the next statement, and so on. We have all done that before!

                      I can't remember whether we have discussed this before, but how/where do you write your Python program code? Do you just sit in a text editor (e.g. Notepad++)? You really needs to sit in an "IDE", which will provide help when writing code but also a visual Python debugger for you to use. There is, for example, PyCharm, which I like, or MS VSCode with Python support loaded in, both of which provide debuggers. You really should switch over to an IDE if you are not using one, it will be the best move you ever make!

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        Julsenn
                        wrote on last edited by
                        #11

                        Hello I have now switched to PyCharm and have localized my error with the print query. Thank you @JonB

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          Julsenn
                          wrote on last edited by
                          #12

                          At this point the Process finished.

                          combotxt = QComboBox.currentText()
                          
                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            You are calling an instance method on a class.

                            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
                            • J Offline
                              J Offline
                              Julsenn
                              wrote on last edited by
                              #14

                              @SGaist
                              Thanks I found my problem

                              Now it works

                                      with open("Slot8.txt", "r") as f:
                                          file_text8 = f.readline()
                              
                                          comboText = self.comboBox.currentText()
                                          if file_text1 == comboText:
                                              self.slot1_4cl()
                              
                              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