C++ QVector中的Qt错误<;T>;::接线员[]:“;“索引超出范围”;在QTextBrowser中

C++ QVector中的Qt错误<;T>;::接线员[]:“;“索引超出范围”;在QTextBrowser中,c++,visual-studio-2010,qt,C++,Visual Studio 2010,Qt,我使用QTextBrowser通过append函数显示字符串 void testing::displaytext() { qRegisterMetaType<QTextCursor>("QTextCursor"); ui.textBrowser->append("Welcome to the world of QT"); ui.textBrowser->append("Welcome to the world of

我使用QTextBrowser通过append函数显示字符串

    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");
    }
void测试::displaytext()
{   
qRegisterMetaType(“QTextCursor”);
ui.textBrowser->append(“欢迎来到QT世界”);
ui.textBrowser->append(“欢迎来到QT世界”);
ui.textBrowser->append(“欢迎来到QT世界”);
ui.textBrowser->append(“欢迎来到QT世界”);
ui.textBrowser->append(“欢迎来到QT世界”);
ui.textBrowser->append(“欢迎来到QT世界”);
ui.textBrowser->append(“欢迎来到QT世界”);
ui.textBrowser->append(“欢迎来到QT世界”);
ui.textBrowser->append(“欢迎来到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
在QVector::operator[]中断言失败:“索引超出范围”,文件c:\iwmake\build\u vs2010\u opensource\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

如何解决此异常?

您应该只调用
QWidget
的成员函数及其gui线程的所有子线程,因为类
QWidget
及其所有子线程(包括
QTextBrowser
)几乎没有任何多线程保证。它们甚至没有记录在案。然而,通过信号触发插槽是线程安全的,可能是解决问题的一种方法

它是由多个线程调用的吗?我应该说得更一般一些:它是由其他线程编写还是读取的?是的,它是由主线程以外的另一个线程编写的。上述函数位于主线程中