[Solved]QThread Output in QTextEdit without emitors.



  • Hello!

    I'm having difficulties with output into QTextEdit Widget from QThread.

    I've tried various ways, but none worked.

    Send the pointer of QTextEdit to QThread, but I get an error, that widgets can't be moved to threads.

    Tried to create QTextEdit inside class inherited by QThread, pass it to MainWindow, where I displayed it, but I get qDebug() "error" into Qt Creator:

    @QObject::connect: Cannot queue arguments of type 'QTextCursor'
    (Make sure 'QTextCursor' is registered using qRegisterMetaType().)@

    Tried to create class inherited by QObject, created QTextEdit inside, adding few functions for threads, created the class in MainWindow and displayed the QTextWidget, and moved the object with moveToThread(); as it should be the "proper way". But I get the same result as at point 2.

    It works, as long thread delay is larger than 2. After that it crashes.
    This is one of the errors thrown into Qt Creator:
    @ASSERT failure in QVector<T>::operator[]: "index out of range", file ....\include/QtCore/../../src/corelib/tools/qvector.h, line 359
    Invalid parameter passed to C runtime function.@

    At point 2 and 3, there is also problem with windows resizing. There is a pretty big possibility that it crashes when resizing on X axis while thread running.

    The reason I'm not using emitors is, that they are slow, and the program crashes sooner that at options two.

    This is last "working" version of my program, so that it'll be a little bit more clear what I mean ( in this version is implemented second option) :
    http://www.2shared.com/file/ZRsSfcdH/Flowchart_Programmer.html

    I'm currently looking for an option, where I can print into QTextEdit with delay 0 ( or at least 1) without crashes.

    Apologies for my bad English and I hope that this makes any sense ;).
    Regards,
    Jake



  • You cannot have any GUI elements outside the main thread. If you want to manipulate GUI elements from other threads you either have to use signals and slots or you have to use invokeMethod(Qt::QueuedConnection) to call the slot, for example QTextEdit::setText(), directly.

    And make sure you've read "Threads, Events and QObjects":http://developer.qt.nokia.com/wiki/Threads_Events_QObjects.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.