PyQt4 TextEdit.clear causes crash

I have a deque type list (a queue) which I'd like to show and update in QTextEdit. There is a function uuenda_kama in class MyForm which should do this (and some other s*** too). First pass of this function when textEdit is empty, it works like a charm, all necessary fields are updated. But on second pass as there has some text added to it, it crashes throwing me a Visual Studio debugger in face. Tried commenting different parts out and came out that line "self.ui.textEdit.clear()" is causing this. What is wrong with it and why is it working on first pass? What can I do to fix it? Code I have right now:

class MyForm(QtGui.QMainWindow):
    ...
    def uuenda_kama(self):
        while True:
        ...
        if vana_que != list(que):
            self.ui.textEdit.clear()
            for i in que:
                self.ui.textEdit.append(i)
            vana_que = list(que)
        sleep(1)

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    myapp = MyForm()
    uuendamine = Thread(target=myapp.uuenda_kama)
    uuendamine.start()
    myapp.show()
    sys.exit(app.exec_())

Answers


You should not be creating a standard python thread outside of the entire app that runs methods on your qwidgets. Instead you should have a QThread that runs non-gui related logic and then emits a signal when it wants the main thread to affect the GUI

Refer to this other question for a good example: Howto change progress by worker thread

You should never call gui methods directly outside of the main thread.


Need Your Help

Replacement for WinRes

.net localization

We have a localization process for a .NET project that relies on Winres to allow non-programmers to adjust control placement and text.

FireBird 2.5: Does BLR contain the related field sizes?

stored-procedures size field firebird

As I know FireBird and InterBase keeps the stored procedures and triggers in BLR (tokenized) format.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.