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

  • SEARCH
  • Home
  • 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 6789583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:37:18+00:00 2026-05-26T17:37:18+00:00

This question seems to have been asked many times in many different forms but

  • 0

This question seems to have been asked many times in many different forms but I haven’t managed to find one with a -relevant to my code- solution.

When I run the program it shows

QObject::installEventFilter: Cannot filter events for objects in a different thread.

Despite this the code works initially but after a while it bombs and python gives an error saying its stopped working.

My code is as follows:

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from xml.etree import ElementTree as ET
import os , time

class LayoutCreator(QDialog):
    def __init__(self , parent=None):
        super(LayoutCreator, self).__init__(parent)
        self.Cameras_Update()


    def Cameras_Update( self ):                                             # Get all shots with camera plots and add them to the cameras_tree
        busyBar = sqrl_QtTools.BusyBar( text = "Gathering Camera Data" )    # Looping progress bar
        busyBar.start()

        # loop through folder structure storing data                

        busyBar.Kill()                                                      # Close looping progress bar    


class BusyBar(QThread):                     # Looping progress bar
    def __init__(self, text = "" ):
        QThread.__init__(self)
        self.text = text
        self.stop = False

    def run( self ):
        self.proBar = QProgressBar()
        self.proBar.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.SplashScreen )
        self.proBar.setMinimum( 0 )
        self.proBar.setMaximum( 100 )
        self.proBar.setTextVisible( True )
        self.proBar.setFormat( self.text )
        self.proBar.setValue( 0 )
        self.proBar.setFixedSize( 500 , 50 )
        self.proBar.setAlignment(Qt.AlignCenter)
        self.proBar.show()
        while not self.stop:                # keep looping while self is visible
            # Loop sending mail 
            for i in range(100):
                progress = self.proBar.value()
                progress = progress + 1
                self.proBar.setValue( progress )

                time.sleep(0.05)
            self.proBar.setValue( 0 )
        self.proBar.hide()

    def Kill(self):
        self.stop = True
  • 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-05-26T17:37:18+00:00Added an answer on May 26, 2026 at 5:37 pm

    You can’t create or access any QWidget outside the main thread.

    You can use signals and slots to indirectly access widgets from the other thread:

    from PyQt4.QtCore import *
    from PyQt4.QtGui import *
    import sys, time
    
    class BusyBar(QThread):                     # Looping progress bar
        # create the signal that the thread will emit
        changeValue = pyqtSignal(int)
        def __init__(self, text = "" ):
            QThread.__init__(self)
            self.text = text
            self.stop = False
            self.proBar = QProgressBar()
            self.proBar.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.SplashScreen )
            self.proBar.setRange( 0, 100 )
            self.proBar.setTextVisible( True )
            self.proBar.setFormat( self.text )
            self.proBar.setValue( 0 )
            self.proBar.setFixedSize( 500 , 50 )
            self.proBar.setAlignment(Qt.AlignCenter)
            self.proBar.show()
    
            self.changeValue.connect(self.proBar.setValue, Qt.QueuedConnection)
            # Make the Busybar delete itself and the QProgressBar when done        
            self.finished.connect(self.onFinished)
    
        def run( self ):
            while not self.stop:                # keep looping while self is visible
                # Loop sending mail 
                for i in range(100):
                    # emit the signal instead of calling setValue
                    # also we can't read the progress bar value from the thread
                    self.changeValue.emit( i )
                    time.sleep(0.05)
                self.changeValue.emit( 0 )
    
        def onFinished(self):
            self.proBar.deleteLater()
            self.deleteLater()
    
        def Kill(self):
            self.stop = True
    
    class LayoutCreator(QDialog):
        def __init__(self , parent=None):
            super(LayoutCreator, self).__init__(parent)
            self.Cameras_Update()
    
        def Cameras_Update( self ):                                       
            # Looping progress bar 
            self.busyBar = BusyBar( text = "Gathering Camera Data" )
            self.busyBar.start()
    
            # loop through folder structure storing data
    
            # Simulate async activity that doesn't block the GUI event loop
            # (if you do everything without giving control back to 
            # the event loop, you have to call QApplication.processEvents()
            # to allow the GUI to update itself )
            QTimer.singleShot(10000, self.stopBar)
    
        def stopBar(self):
            self.busyBar.Kill()                        # Close looping progress bar    
    
    app = QApplication(sys.argv)
    win = LayoutCreator()
    win.show();
    sys.exit(app.exec_())
    

    Or

    If you only want a busy indicator, you can simply set both the minimum and maximum of the QProgressBar to 0, and you won’t need a thread, as indicated in the documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question seems to have been asked a lot, but I haven't seen an
This question has been asked many times before but it seems everyone else is
I've searched SO and this question seems to have been asked multiple times, but
I know this question has been asked many times on here but I have
i know that this is a famous question and have been asked many times.
This question seems to have been asked but without enough results for me. I
I know similar questions have been asked many times befor, but I think this
I have seen this question asked many times but none of the answers seem
I thought this question would have been asked before, but I couldn't find it
I realize this question has been asked several times in several different forms ,

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.