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. Calling methods of PyQt objects in a thread.
Forum Updated to NodeBB v4.3 + New Features

Calling methods of PyQt objects in a thread.

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 286 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.
  • N Offline
    N Offline
    nfoert
    wrote on 2 Apr 2022, 14:22 last edited by
    #1

    Im relatively new to PyQt. Can someone help explain the best way to call something like

    window.show()
    

    from a thread? When I run this, my thread (and program) terminates without an error.

    My program is doing some work in a thread before showing the main window. Using

    label.SetText()
    

    on a label to display progress works, but when using

    window.show()
    

    the program stops.

    I’m using Qt Designer to make my user interfaces.
    Thank you!

    J 1 Reply Last reply 2 Apr 2022, 14:33
    0
    • N nfoert
      2 Apr 2022, 14:22

      Im relatively new to PyQt. Can someone help explain the best way to call something like

      window.show()
      

      from a thread? When I run this, my thread (and program) terminates without an error.

      My program is doing some work in a thread before showing the main window. Using

      label.SetText()
      

      on a label to display progress works, but when using

      window.show()
      

      the program stops.

      I’m using Qt Designer to make my user interfaces.
      Thank you!

      J Offline
      J Offline
      JonB
      wrote on 2 Apr 2022, 14:33 last edited by JonB 4 Feb 2022, 14:38
      #2

      @nfoert

      window.show()

      You can't. Because Qt does not allow any UI operations to be performed from any thread other than the main thread used to display the UI. That actually applies just as much to QLabel.setText() as it does to QWidget.show(), so you are lucky if you see either of these work from a thread.

      As a general observation, especially if you are new to Qt/PyQt. Threads are the last thing you want to use if you can avoid it. A large number of beginners try to use threads from the start, for no reason/they run into difficulties. So the first thing to ask yourself is why you need a thread at all.

      BTW Qt has QProgressBar or QProgressDialog classes to display progress.

      1 Reply Last reply
      2

      1/2

      2 Apr 2022, 14:22

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved