Linked Questions

Popular Questions

Here in my program i need to call a main window function in thread class.I tried many ways but i got gui is not safety error i didn't get the output here is my sample code can any one please help me how to call a function in thread class.Please help me.

my sample code:

import time
from PyQt4 import QtGui,QtCore
global p
class OpenOMX(QtCore.QThread):
    statusChanged = QtCore.pyqtSignal(int)

    def __init__(self):
        QtCore.QThread.__init__(self)


    def run(self):
         while True:
            # try:

                self.statusChanged.emit(status)
                print "connect"
            # except:
            #     pass

class Table_Program(QtGui.QMainWindow):
    def __init__(self, parent=None):
        super(Table_Program, self).__init__(parent)
        self.w = QtGui.QWidget()
        self.openOMX = OpenOMX()
        self.openOMX.statusChanged.connect(self.click_me)

        self.mainLayout = QtGui.QVBoxLayout(self.w)
        self.btn = QtGui.QPushButton("click")
        self.btn.clicked.connect(self.click_me)
        self.mainLayout.addWidget(self.btn)
        self.setCentralWidget(self.w)

    def click_me(self):
        print "click me"

if __name__ == '__main__':
    import sys
    global p
    app = QtGui.QApplication(sys.argv)
    p = Table_Program()
    p.show()
    app.exec_()

Related Questions