question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PySide6 QTimer.timeout.connect does not work within QMainWidget, but in QApplication

See original GitHub issue

Hi,

I’ve made a PySide6 GUI application with several QTimer objects within widgets.

If I execute the application with python, everything is fine. Also deployed with cx_freeze.

Now I’ve tried nuitka with following command: python.exe -m nuitka --mingw64 --standalone test.py --plugin-enable=pyside6 --plugin-enable=pylint-warnings --follow-imports

The result does not work, since the methods connected to the timers are not executed. I’ve made 2 small examples you can find at the end.

  • Nuitka version, full Python version and Platform (Windows, OSX, Linux …)

    python -m nuitka --version

0.6.16.4
Python: 3.9.4 (tags/v3.9.4:1f2e308, Apr  6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)]
Executable: C:\Users\Bad\AppData\Local\Programs\Python\Python39\python.exe
OS: Windows
Arch: x86_64
  • How did you install Nuitka and Python

installed via pip. No venv

  • The specific PyPI names and versions

    python -m pip freeze

PySide6==6.1.3
#%%
import sys
from PySide6.QtWidgets import QApplication, QMainWindow
from PySide6.QtCore import QTimer

class MainWidget(QMainWindow):
    def __init__(self, parent=None):
        super(MainWidget, self).__init__(parent)
        self.timer = QTimer(self) #self
        self.timer.timeout.connect(self.update)
        self.timer.start(1000)
        self.count = 0

    def update(self):
        self.count += 1
        print ("update ",self.count)
        if self.count >5:
            self.timer.stop()
            self.close()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    mymain = MainWidget()
    mymain.show()
    sys.exit(app.exec())

Expected output:

>test.exe
update 1
update 2
update 3
update 4
update 5
update 6

Working Example - QTimer within QApplication:

#%%
import sys
from PySide6.QtWidgets import QApplication
from PySide6.QtCore import QTimer

class MainApp(QApplication):
    def __init__(self, parent=None):
        super(MainApp, self).__init__(parent)
        self.timer = QTimer(self) #self
        self.timer.timeout.connect(self.update)
        self.timer.start(1000)
        self.count = 0

    def update(self):
        self.count += 1
        print ("update",self.count)
        if self.count >5:
            self.timer.stop()
            self.exit()

if __name__ == "__main__":
    app = MainApp(sys.argv)
    sys.exit(app.exec())

Any idea?

Best regards Bastian

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kayhayencommented, Sep 16, 2021

Well, that’s of course not right. I am not sure it’s a bug of yours, I am pretty sure it’s one of ours, Nuitka and/or PySide6 here, but at least you now have a workaround. I cannot work on this right away, but it seems important, and so this will be dealt with eventually.

However, thanks for the good report, and sticking with me on this. 😃

1reaction
kayhayencommented, Sep 16, 2021

This does it for me, thank you, but I am totally confused as to what the difference could be. But once I know the bug, maybe I can tell why it was working for me with the other example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Problem with QTimer() function in PySide6 the ...
I have this PySide app and I want to run the function pp every 1 second, but when I run the app it...
Read more >
QTimer - Qt for Python
The QTimer class provides a high-level programming interface for timers. To use it, create a QTimer , connect its timeout() signal to the...
Read more >
Multithreading PyQt5 applications with QThreadPool
Run background tasks concurrently without impacting your UI. A common problem when building Python GUI applications is.
Read more >
Python GUI with PyQT/PySide2
PyQT Is QT for python, but it's not part of the QT company due to licensing issues, it's developed/offered by a company called...
Read more >
Thread: QTimer don't start
Hi I have a problem with QTimer, I call the start function but don't work: class MyClass : public QObject { Q_OBJECT private:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found