Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2355

Repeated QTimer.singleShot() reuses values captured previously

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 6.5.1
    • PySide
    • None
    • Windows

    Description

      Code (test_bug.py):

      from PySide6.QtCore import QObject, QTimer
      from pytestqt.qtbot import QtBot
      
      MS = 10
      
      class MyObject(QObject):
          def fun(self, value: int) -> None:
              self.value = value
              QTimer.singleShot(MS, lambda: print(f"({self.value}, {value}); ", end=""))
      
      def test_bug(qtbot: QtBot) -> None:
          my_object = MyObject()
          for i in range(10):
              my_object.fun(i)
              qtbot.wait(2 * MS) 

       
      Command line:

      pytest test_bug.py -s

       
      Output with 6.5.0 (correct):

      ======================================================================================== test session starts =========================================================================================
      platform win32 -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
      PySide6 6.5.0 -- Qt runtime 6.5.0 -- Qt compiled 6.5.0
      rootdir: C:\Code
      plugins: pylama-8.4.1, qt-4.2.0
      collected 1 item
      test_bug.py (0, 0); (1, 1); (2, 2); (3, 3); (4, 4); (5, 5); (6, 6); (7, 7); (8, 8); (9, 9); .
      ========================================================================================= 1 passed in 0.26s ========================================================================================== 
       
      

       

      Output with 6.5.1 (wrong, I would say):

      ======================================================================================== test session starts =========================================================================================
      platform win32 -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
      PySide6 6.5.1 -- Qt runtime 6.5.1 -- Qt compiled 6.5.1
      rootdir: C:\Code
      plugins: pylama-8.4.1, qt-4.2.0
      collected 1 item                                                                                                                                                                                       
      test_bug.py (0, 0); (1, 0); (2, 0); (3, 0); (4, 0); (5, 0); (6, 0); (7, 0); (8, 0); (9, 0); .
      ========================================================================================= 1 passed in 0.40s ========================================================================================== 
      

       

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              crmaurei Cristian Maureira-Fredes
              bers bers bers
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes