从QCoreApplication :: processEvents

时间:2018-07-27 15:24:56

标签: opengl qt5 qtopengl

我正在使用QOpenGLWidget将OSX应用程序从Qt 4 / Carbon转换为Qt5.11。

我已经将图形“调用”移动到了我覆盖的QOpenGlWidget :: paintGL()。

问题是我仍然在控制台上收到这些消息:

QWidget :: paintEngine:应该不再被调用

获取堆栈跟踪信息后,我发现它最终是从QCoreApplication :: processEvents调用的,它是从我自己的内部事件循环中调用的。

这是堆栈跟踪(为便于阅读而进行了编辑)

  • 线程#1,队列='com.apple.main-thread',停止原因=断点1.1
    • 帧#0:libQt5Widgets_debug.5.dylib QWidget::paintEngine() frame #1: libQt5Widgets_debug.5.dylib QOpenGLWidget :: paintEngine(0) 框架2:libQt5Gui_debug.5.dylib QPainter::begin() frame #3: libQt5Gui_debug.5.dylib QPainter :: QPainter() 框架#4:libQt5Gui_debug.5.dylib QPainter::QPainter() frame #5: libQt5Widgets_debug.5.dylib QWidgetPrivate :: drawWidget() 框架6:libQt5Widgets_debug.5.dylib QWidgetPrivate::repaint_sys() frame #7: libQt5Widgets_debug.5.dylib QWidgetPrivate :: syncBackingStore() 框架#8:libQt5Widgets_debug.5.dylib QWidgetWindow::handleExposeEvent() frame #9: libQt5Widgets_debug.5.dylib QWidgetWindow :: event() 框架#10:libQt5Widgets_debug.5.dylib QApplicationPrivate::notify_helper() frame #11: libQt5Widgets_debug.5.dylib QApplication :: notify() 框架#12:libQt5Core_debug.5.dylib QCoreApplication::notifyInternal2() frame #13: libQt5Gui_debug.5.dylib QCoreApplication :: sendSpontaneousEvent() 框架#14:libQt5Gui_debug.5.dylib QGuiApplicationPrivate::processExposeEvent() frame #15: libQt5Gui_debug.5.dylib QGuiApplicationPrivate :: processWindowSystemEvent() 框架#16:libQt5Gui_debug.5.dylib bool QWindowSystemInterfacePrivate::handleWindowSystemEvent<QWindowSystemInterface::SynchronousDelivery>() frame #17: libQt5Gui_debug.5.dylib无效QWindowSystemInterface :: handleExposeEvent() 框架#18:libqcocoa_debug.dylib QCocoaWindow::handleExposeEvent() frame #19: libqcocoa_debug.dylib ::-[QNSView updateRegion:](self = 0x000061200039fc40,_cmd =“ updateRegion:”,dirtyRegion = QRegion @ 0x00007ffeefbf9b18) 框架#20:libqcocoa_debug.dylib ::-[QNSView updateLayer](self=0x000061200039fc40, _cmd="updateLayer") frame #21: AppKit _ NSViewUpdateLayer + 45 框架#22:AppKit -[_NSViewBackingLayer display] + 495 frame #23: QuartzCore CA :: Layer :: display_if_needed(CA :: Transaction *)+ 634 框架#24:QuartzCore CA::Context::commit_transaction(CA::Transaction*) + 319 frame #25: QuartzCore CA :: Transaction :: commit()+ 576 第26帧:QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 66 frame #27: CoreFoundation CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23 框架#28:CoreFoundation __CFRunLoopDoObservers + 452 frame #29: CoreFoundation CFRunLoopRunSpecific + 523 第30帧:HIToolbox RunCurrentEventLoopInMode + 293 frame #31: HIToolbox ReceiveNextEventCommon + 618 框架#32:HIToolbox _BlockUntilNextEventMatchingListInModeWithFilter + 64 frame #33: AppKit _ DPSNextEvent + 997 框架#34:AppKit -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1362 frame #35: libqcocoa_debug.dylib QCocoaEventDispatcher :: processEvents(this = 0x00006040000dbdf0,flags =(i = 0))在qcocoaeventdispatcher.mm:482 框架#36:在qcoreapplication.cpp:1252处的libQt5Core_debug.5.dylib`QCoreApplication :: processEvents(flags =(i = 0))

问题在于:: processEvents最终为QOpenGLWidget调用了:: paintEngine,而:: OpenGL却不在此了,但这完全超出了我的控制范围。

FWIW,驱动它的事件是QEvent :: UpdateRequest。

我尝试在QOpenGLWidget继承类中重写:: event,以在收到QEvent :: UpdateRequest时调用QOpenGlWidget :: update,但这最终导致应用程序无响应。

我应该如何处理:: processEvents尝试绘制QOpenGlWidgets?

谢谢!

1 个答案:

答案 0 :(得分:1)

我通过从QOpenGlWidget子类中删除以下语句来解决此问题:

setAttribute(Qt :: WA_PaintOnScreen,true);

消除这一麻烦的paintEngine调用(并解决了所有其他问题)。