c++ - Qt 在 QTextBrowser 中的 QVector<T>::operator[]: "index out of range"中抛出 ASSERT 失败

标签 c++ visual-studio-2010 qt

我正在使用 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/

相关文章:

c++ - flann索引使用LshIndexParams需要什么类型的数据?

c++ - 无法将指向 const 数据的指针作为函数模板参数传递

c++ - 如何将结果从std::thread传回给Qt中的Gui主线程?

c++ - Qt 语言学家和谷歌翻译

c++ - qmake转cmake链接错误

c++ - 如何将此代码从 Dijkstra 转换为 Astar?

c++ - 将十进制数转换为二进制数的意外结果

c++ - 在 Visual Studio 2010 中调试由 C++ 程序调用的 Fortran dll

c++实现在dll外部定义的虚拟类,在dll中

visual-studio - 我可以查看 MSBuild 实际执行了哪些构建命令吗?