Reputation: 45
I am using QTextBrowser to display string through append function.
void testing::displaytext()
{
qRegisterMetaType<QTextCursor>("QTextCursor");
ui.textBrowser->append("Welcome to the world of QT");
ui.textBrowser->append("Welcome to the world of QT");
ui.textBrowser->append("Welcome to the world of QT");
ui.textBrowser->append("Welcome to the world of QT");
ui.textBrowser->append("Welcome to the world of QT");
ui.textBrowser->append("Welcome to the world of QT");
ui.textBrowser->append("Welcome to the world of QT");
ui.textBrowser->append("Welcome to the world of QT");
ui.textBrowser->append("Welcome to the world of QT");
}
The above function is being called by a thread in regular intervals, but after being called for sometimes it is throwing this error:
ASSERT failure in QVector<T>::operator[]: "index out of range", file c:\iwmake\build_vs2010_opensource_________________padding_________________\include\qtcore\../../src/corelib/tools/qvector.h
How can i resolve this exception?
Upvotes: 2
Views: 4479
Reputation: 23610
You should only call member functions of QWidget
and all its descendents from the gui thread, because the class QWidget
and hence also all its descendents including QTextBrowser
have hardly any multi-threading guarantees. They are not even reentrant as documented here. However, triggering slots through signals is thread-safe and might be a solution to your problem.
Upvotes: 3