2016-04-07 14 views
0

Birisi bana explane kodumu nasıl kullanmalıyım, ya da yanlış yapıyorum? 'view_splash' işlevini çalıştırmak için 'btn_run' tuşunu kullanmak istiyorum. Ama bir şeyler yanlış gidiyor, ama 'view_splash' başlamayacak. Bana hata göstermiyor.QtCore.SIGNALS kodumda çalışma

import sys 
from PyQt4 import QtGui, QtCore 
import time 


class Window(QtGui.QMainWindow): 

def __init__(self): 
    super(Window, self).__init__() 
    self.setGeometry(500, 150, 500, 600) 
    self.setWindowTitle('Test GUI') 

    self.threadclass = AThread() 
    self.connect(self.threadclass, QtCore.SIGNAL("view_splash()"), self.view_splash) 

    self.home() 

def home(self): 
    btn_run = QtGui.QPushButton("Run", self) 
    self.threadclass = AThread() 
    btn_run.clicked.connect(self.threadclass.start) 
    btn_run.resize(120, 40) 
    btn_run.move(190, 540) 

    self.show() 

def view_splash(self): 
    print('test') 
    label = QLabel("<font color=red size=10<b>" + "SPLASH" + "</b></font>") 
    label.setWindowFlags(Qt.SplashScreen | Qt.WindowStaysOnTopHint) 
    label.show() 
    QtCore.QTimer.singleShot(5000, label.close) 


class AThread(QtCore.QThread): 
def __init__(self): 
    super(AThread, self).__init__() 

def run(self): 
    print(1) 
    print(2) 
    time.sleep(5) 
    print(3) 
    print(4) 
    self.emit(QtCore.SIGNAL("view_splash()")) 


app = QtGui.QApplication(sys.argv) 
GUI = Window() 
sys.exit(app.exec_()) 
+0

deneyin (http://pyqt.sourceforge.net/Docs/PyQt4/new_style_signals_slots.html). Genellikle bu, bu gibi sorunları giderir. –

cevap

0

Sinyalleri farklı şekilde oluşturup bağlamanız gerekir. [Sinyalleri ve yuvaları yeni stil] kullanılarak

class AThread(QtCore.QThread): 
    view_splash = QtCore.pyqtSignal() 

    def run(self): 
     ... 
     self.view_splash.emit() 

class Window(QtGui.QMainWindow): 

    def __init__(self): 
     ... 
     self.threadclass.view_splash.connect(self.view_splash) 
İlgili konular