"""
Minimum example to trigger a bug in PySide6.

The Qt framework prints the following error message during the call to
timer.timeout.connect() :

  QObject: Cannot create children for a parent that is in a different thread.

Issue occurs with PySide 6.8.3, 6.9.0, 6.9.1 on Linux and Windows 11.
Issue occurs with Python 3.11.2 and Python 3.13.3. 
Issue occurs on on Linux and Windows 11.
Issue does not occur with PySide 6.7.3.
"""

from PySide6.QtCore import Slot, QThread, QTimer
from PySide6.QtWidgets import QApplication

class MyThread(QThread):

    def run(self):
        timer = QTimer()
        print("timer thread:", timer.thread())
        print("current thread:", QThread.currentThread())
        print("now connecting timeout signal")
        timer.timeout.connect(self.on_timeout)
        print("done connecting timeout signal")
        timer.start(1000)
        self.exec()

    # Slot() -- adding this decorator does not affect the issue
    def on_timeout(self):
        print("timeout")
        self.quit()
        app.quit()

app = QApplication()
thread = MyThread()

# Uncommenting the following line makes the issue go away:
# thread.started.connect(lambda: print("started"))

thread.start()
app.exec()
thread.wait()

