我正在使用 QTextBrowser 通过附加功能显示字符串。
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");
}
上面的函数被线程定期调用,但是之后 有时被调用会抛出此错误:
ASSERT failure in QVector<T>::operator[]: "index out of range", file c:\iwmake\build_vs2010_opensource_________________padding_________________\include\qtcore\../../src/corelib/tools/qvector.h
如何解决此异常?
最佳答案
您应该只从 gui 线程调用 QWidget
及其所有后代的成员函数,因为类 QWidget
及其所有后代包括 QTextBrowser
几乎没有任何多线程保证。他们甚至不是reentrant如记录here 。但是,通过信号触发插槽是线程安全的,并且可能是您问题的解决方案。
关于c++ - Qt 在 QTextBrowser 中的 QVector<T>::operator[]: "index out of range"中抛出 ASSERT 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16941366/