[Solved] PyQt: RuntimeError: wrapped C/C++ object has been deleted & has no attribute of flush in python

After redirecting the command line output to the UI interface in the previous article, an error will be reported when closing the UI interface

Has no attribute of flush in Python or

PyQt: RuntimeError: wrapped C/C++ object has been deleted

The solution is to add a function in the class to which the command line output is redirected:

class ButtonOne(QThread):
    _signalForText = pyqtSignal(str)
 
    def __init__(self):
        super(ButtonOne, self).__init__()
 
    def write(self, text):
        self.signalForText.emit(text)
 
    def run(self):
 
        for i in range(15):
            time.sleep(1)
            print(i)
        print('end')
 
    @property
    def signalForText(self):
        return self._signalForText
    
    def flush(self):
        pass

This can be solved.

The added functions are:

def flush(self):
    pass

Read More: