- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在上传大量纹理(每秒 60 个 VGA 图像)并且它阻塞了我的 UI 线程。来自 the Qt 5.1 QGLWidget manual page (强调我的):
Texture uploading in a thread. Doing texture uploads in a thread may be very useful for applications handling large amounts of images that needs to be displayed, like for instance a photo gallery application. This is supported in Qt through the existing bindTexture() API. A simple way of doing this is to create two sharing QGLWidgets. One is made current in the main GUI thread, while the other is made current in the texture upload thread. The widget in the uploading thread is never shown, it is only used for sharing textures with the main thread. For each texture that is bound via bindTexture(), notify the main thread so that it can start using the texture.
QObject::moveToThread: Widgets cannot be moved to a new thread
bindTexture()
在 UI 线程外执行。
最佳答案
答案有点晚,但是小部件需要由创建它们的线程移动到新线程。在你的情况下是这样的:
QGLWidget *glWidget=new QGLWidget();
QThread *newThread=new QThread();
glWidget->doneCurrent();
glWidget->context()->moveToThread(newThread);
virtual void glInit();
virtual void glDraw();
virtual void initializeGL();
virtual void resizeGL(int width, int height);
virtual void paintGL();
QGLWidget ( QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WindowFlags f = 0 )
QGLWidget ( QGLContext * context, QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WindowFlags f = 0 )
QGLWidget ( const QGLFormat & format, QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WindowFlags f = 0 )
QGLWidget *glWidget=new QGLWidget();
GLWidget *threadedWidget=new GLWidget(0/*parent*/, glWidget);
QThread *newThread=new QThread();
threadedWidget->moveToThread(newThread);
关于multithreading - QGLWidget 在另一个线程中?文档指的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18345356/
我是一名优秀的程序员,十分优秀!