Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9152549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:04:43+00:00 2026-06-17T12:04:43+00:00

Issue I have a PyQt GUI where the user presses a button to start

  • 0

Issue

I have a PyQt GUI where the user presses a button to start a background thread (workerThread, which is subclassed from QThread). I would like to have a timer display (in the form of a QLabel) to show how much time has elapsed since workerThread started, and I would like this timer to stop as soon as the workerThread exits.

Possible solution

I’ve thought about creating another independent thread (timerThread) that uses a QTimer to send a signal to a slot to update the QLabel in the main GUI thread with the elapsed time every 1 second. This timerThread will exit as soon as it receives a terminate signal from workerThread.

However, I’d have to start timerThread at the same time as WorkerThread, and I’m not sure how to this.

Question

Is there an easier way to do this? Is QTimer even the right approach to start with?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:04:45+00:00Added an answer on June 17, 2026 at 12:04 pm

    Here is one way of doing this. In this example, myThread starts the timerThread as a child process when it’s run method is called. It’s timeElapsed signal is connected to the timerThreads timeElapsed signal. The timerThread will check each second while the parent isRunning and emit a timeElapsed signal if True:

    #!/usr/bin/env python
    #-*- coding:utf-8 -*-
    
    import time
    
    from PyQt4 import QtCore, QtGui
    
    class timerThread(QtCore.QThread):
        timeElapsed = QtCore.pyqtSignal(int)
    
        def __init__(self, parent=None):
            super(timerThread, self).__init__(parent)
            self.timeStart = None
    
        def start(self, timeStart):
            self.timeStart = timeStart
    
            return super(timerThread, self).start()
    
        def run(self):
            while self.parent().isRunning():
                self.timeElapsed.emit(time.time() - self.timeStart)
                time.sleep(1)
    
    
    class myThread(QtCore.QThread):
        timeElapsed = QtCore.pyqtSignal(int)
        def __init__(self, parent=None):
            super(myThread, self).__init__(parent)
    
            self.timerThread = timerThread(self)
            self.timerThread.timeElapsed.connect(self.timeElapsed.emit)
    
        def run(self):
            self.timerThread.start(time.time())
    
            iterations = 3
            while iterations:
                print "Running {0}".format(self.__class__.__name__)
                iterations -= 1
                time.sleep(2)        
    
    
    class myWindow(QtGui.QWidget):    
        def __init__(self):
            super(myWindow, self).__init__() 
    
            self.button = QtGui.QPushButton(self)
            self.button.setText("Start Threading!")
            self.button.clicked.connect(self.on_button_clicked)
    
            self.label = QtGui.QLabel(self)
    
            self.layout = QtGui.QVBoxLayout(self)
            self.layout.addWidget(self.button)
            self.layout.addWidget(self.label)
    
            self.myThread = myThread(self)
            self.myThread.timeElapsed.connect(self.on_myThread_timeElapsed)
            self.myThread.finished.connect(self.on_myThread_finished)
    
        @QtCore.pyqtSlot()
        def on_button_clicked(self):
            self.myThread.start()
    
        @QtCore.pyqtSlot(int)
        def on_myThread_timeElapsed(self, seconds):
            self.label.setText("Time Elapsed: {0}".format(seconds))
    
        @QtCore.pyqtSlot()
        def on_myThread_finished(self):
            print "Done"
    
    if __name__ == "__main__":
        import sys
    
        app = QtGui.QApplication(sys.argv)
        app.setApplicationName('myWindow')
    
        main = myWindow()
        main.show()
    
        sys.exit(app.exec_())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi guys I am having issue I have this query: SELECT * FROM useraccount
Issue: I have a Mootools Request object which sends a GET request to a
i have the follow issue : I have a point which is setted at
I have the following issue.I have a camera with lookAt method which works fine.I
I have issue where i want to create Dynamic function which will do some
Issue : I have Json coming back from the server. The Json is an
Issue: I have a standard subclassed NSManagedObject (see below). I have a view controller
Issue: I have a WPF fullscreen application, which acts as a dashboard. The computer
i have issue with Droid X phone for sending attached email from my Application.My
I have issue, after checkout on checkout/onepage/success get a user info using order id,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.