Linux中的Qt线程问题 [英] Qt Threading Issues in Linux

查看:435
本文介绍了Linux中的Qt线程问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的项目上使用Qt进行开发了一段时间,并且我们开始转向更加面向线程的设计.将某些GL渲染小部件移至其他线程后,我发现了一些非常奇怪的行为.看来,如果GL窗口小部件在接受用户输入的窗口小部件(例如QTextEdit)抢占焦点之前开始从另一个线程(增强线程或QThread)进行更新,我将看到XCB崩溃,如下所示:

I have been developing with Qt for some time now on my project, and we are starting to move to a more thread-oriented design. Upon moving some GL rendering widgets to other threads I have discovered some very weird behavior. It appears that if a GL Widget begins updating from another thread (boost thread or QThread) before a widget that accepts user input (such as a QTextEdit) grabs focus, I get XCB crashes that look like:

[xcb] Too much data requested from _XRead
[xcb] This is most likely caused by a broken X extension library
[xcb] Aborting, sorry about that.
hypnotizer: ../../src/xcb_io.c:735: _XRead: Assertion ‘!xcb_xlib_too_much_data_requested’ failed.

为了测试这一点,我实际上可以对GLHypnotizer演示进行简单的修改以重现崩溃.可以在以下位置找到该演示: http://qt-project.org/doc/qt-4.8 /demos-glhypnotizer.html [qt-project.org]

To test this out, I actually can make a simple modification to the GLHypnotizer demo to reproduce the crash. That demo can be found here: http://qt-project.org/doc/qt-4.8/demos-glhypnotizer.html [qt-project.org]

如果我在第313行左右(在调用newThread()之前)添加了行'mdiArea.addSubWindow(new QTextEdit(this));',那么在演示开始时,将有一个QTextEdit和GL Hypnotizer Widget .如果再单击QTextEdit来获取焦点,则每次都会发生上述崩溃.

If I add the line ‘mdiArea.addSubWindow(new QTextEdit(this));’ at around line 313 (before the call to newThread()), then when the demo starts there will be a QTextEdit and a GL Hypnotizer Widget. If I then click on the QTextEdit to grab focus I will get the above crash every time.

任何人都可以使用上述说明在Linux安装上重现该错误吗?以前有人在使用Qt和线程的Linux上遇到过这类问题吗?

Can anyone reproduce the error on there Linux install using the above instructions? Has anyone encountered these types of issues on Linux using Qt and threading before?

注意:我正在使用Ubuntu 12,并且在VirtualBox和非VirtualBox Ubuntu安装中会发生此崩溃

Note: I am using Ubuntu 12 and this crash happens in VirtualBox and non VirtualBox Ubuntu installations

推荐答案

OpenGL,Qt渲染和多线程处理效果不佳.特别是,OpenGL上下文一次只能在一个线程中处于活动状态.现在,如果上下文在多个小部件之间共享(请注意,这与在上下文之间共享对象不同,那么我说的是用于多个合法窗口/小部件的单个上下文),并且这些小部件将从您正在使用的不同线程中渲染陷入很多问题.

OpenGL, Qt rendering and multithreading don't mix well. In particular a OpenGL context can be active in only one thread at a time. Now if the context is shared among multiple widgets (note that this different from sharing objects between contexts, I'm talking about a single context that's used for multiple windows/widgets which is legitimate) and those widgets render from different threads you're going to get into a lot of issues.

通常,对于OpenGL和多线程,最好的做法是不这样做.是的,请使用多个线程,但是将它们用于与OpenGL无关的所有内容或任何类型的图形输出.将所有图形操作都留在一个线程中,以避免出现重大问题.

Usually the best course of action when it comes to OpenGL and multithreading is, not doing it. Use multiple threads, yes, but use them for everything that's not related to OpenGL or any kind of graphics output. Keep all graphics operations to a single thread to avoid major issues.

这篇关于Linux中的Qt线程问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆