Frage

I try to get the value of Count_total_value in my user interface when I call Continusread method, (it should be "toto" according to what I want to do) but it is always the default value "azerty" which is displayed. Please can you tell me where I am wrong?

This is my code:

#!/usr/bin/env python3
from PyQt4 import QtCore, QtGui

import sys
import os
import subprocess
import time
import threading
from ctypes import *
import ctypes
#import Converted Python UI File
from test_error_rx import Ui_MainWindow

class MyThread(QtCore.QThread):
    Count_total_valuechanged = QtCore.pyqtSignal(str)

    def __init__(self, parent=None):
        super(MyThread, self).__init__(parent=parent)
        self.Count_total_value = 'Azerty'

    def run(self):
    ##do things to calculate Count_total_value
        Count_total_value='toto'
        self.Count_total_valuechanged.emit((self.Count_total_value))
        time.sleep(0.1)


class Main( QtGui.QMainWindow,QtGui.QWidget):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        # Connect the Buttons
        QtCore.QObject.connect(self.ui.Continusread,QtCore.SIGNAL("clicked()"),self.Continusread)

        self.__thread = MyThread(self)
        self.__thread.Count_total_valuechanged.connect(self.ui.Count_total.setText)

    def Continusread(self):
       self.__thread.start()

    def main():
        app = QtGui.QApplication(sys.argv)
        window = Main()
        window.show()
        sys.exit(app.exec_())

    if __name__ == "__main__":
        main()
War es hilfreich?

Lösung

In the run() method of your thread class MyThread you set Count_total_value='toto' when it should be self.Count_total_value='toto'.

Note that when posting on stackoverflow you should:

  1. post a minimilistic working example (you haven't included your UI in the above code so no-one can run your script)
  2. Check the posted code has the correct indentation and fix any mistakes (your posted code is a mess of incorrect indentation)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top