Results 1 to 3 of 3

Thread: PyQt4 will only run in main???

  1. #1
    Join Date
    May 2008
    Location
    127.0.0.1
    Beans
    187
    Distro
    Ubuntu 13.04 Raring Ringtail

    PyQt4 will only run in main???

    I am programming in python 2.6 from repo and I am attempting to thread my gui using OyQt4.

    When I did a Tk GUI I was able to run the GUI in a separate thread no problem, but when I try to do the same with QT I get errors.
    Is my supposition that Qt4 will only run from the Main thread?

    Code:
    import os
    import pickle
    import sys
    import threading
    import time
    
    import SW_CharacterX
    import SW_CombatX
    import SW_CharacterCreator
    
    #Qt gui boilerplate
    from PyQt4 import QtGui, QtCore
    import SW_Gui_Qt
    
    
    class ThaThread ( threading.Thread ):
    
       def run ( self ):
            #RUN CHARACTER CREATOR
            SW_CharacterCreator.main()  
            #RUN COMBAT
            SW_CombatX.Combat()
                
    def main():
        #Again, Qt boilerplate...
        app = QtGui.QApplication(sys.argv)
        window = SW_Gui_Qt.MainWindow()  
        window.show()
        sys.exit(app.exec_())    
    
        return(0) 
        
    
    if __name__ == '__main__':
    
        try:
            ThaThread().start()          
        except:
            print ("NO THREADING AVAILABLE")
            import sys
            sys.exit(1)
    
        main()
    
    main
    Is this the only way to do this or is there a better way?

    Thank you in advance!
    Last edited by xaegis; September 26th, 2010 at 05:07 PM.

  2. #2
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,215
    Distro
    Ubuntu Mate 15.04 Vivid Vervet

    Re: PyQt4 will only run in main???

    Quote Originally Posted by xaegis View Post
    When I did a Tk GUI I was able to run the GUI in a separate thread no problem, but when I try to do the same with QT I get errors.
    Is my supposition that Qt4 will only run from the Main thread?
    See http://doc.trolltech.com/4.6/threads-starting.html "In GUI applications, the main thread is also called the GUI thread because it's the only thread that is allowed to perform GUI-related operations."

    This also applies to PyQt.

  3. #3
    Join Date
    May 2008
    Location
    127.0.0.1
    Beans
    187
    Distro
    Ubuntu 13.04 Raring Ringtail

    Re: PyQt4 will only run in main???

    That is what I needed to know. Thanks!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •