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. [bug?]One specific value run code piece twice

[bug?]One specific value run code piece twice

Scheduled Pinned Locked Moved Solved Qt for Python
2 Posts 1 Posters 621 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
    dancaer69
    wrote on last edited by
    #1

    I'm new to python and pyqt(I'm using pycharm as IDE), so I don't know if this is a bug or is something wrong with my code?
    I have a text file with greek words one at a line, with capital letters. I'm using QFile and QTextStream to check if the given word exists in this file. This is the piece of code:

        def checkWrd(self):
            correctWord=""
            datafile = QFile(":resources/dict/words.txt")
            if not datafile.open(QIODevice.ReadOnly | QIODevice.Text):
                return
            stream=QTextStream(datafile)
            stream.seek(0)
            while not datafile.atEnd():
                line=stream.readLine()
                if len(self.MYWORD)>1 and line==self.MYWORD and not self.wordsList.findItems(line,Qt.MatchExactly):
                    print(line)
                    correctWord=correctWord+line
            datafile.close()
            return correctWord
    

    This works fine except 1 specific word. I have tested a lot of times other different words and only on that I have this strange behaviour. The word is "ΤΙΣ"
    I also checked this word in the text file and I replaced it myself with greek capital leters.
    The problem is that the word changes to "ΤΙΣΤΙΣ" and also doesn't respect other restrictions, as to don't readded to the list.
    I put 2 breakpoints in debugger on the lines:

         print(line)
         correctWord=correctWord+line
    

    and Ι can see that on this specific word these to lines executed twice, so the result is "ΤΙΣΤΙΣ"
    When I input the word and press the button to run the check method the program breaks to the first breakpoint. By pressing the debugger's "resume program" button, it breakes to the next break point.
    In all other words i checked, after that it continues to the next code and the word appears correct.
    But for that specific word, it jumbs again to the first breakpoint, and after to the second. So these to lines executed twice.
    Any ideas why this happens?

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

      I answering myself because I think I found the issue. Seems that sothing was wrong with the file. And because I'm loading the file from the resources was needed to recompile the resources file for changes to the file to applied. I thought that the file read from its path, but seems that from resources is loading an instance of the file and not the file itself.
      Anyway, seems that my issue solved.

      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