我正在使用 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.dylibQPainter::begin() frame #3: libQt5Gui_debug.5.dylib
QPainter::QPainter() 帧#4:libQt5Gui_debug.5.dylibQPainter::QPainter() frame #5: libQt5Widgets_debug.5.dylib
QWidgetPrivate::drawWidget() 帧#6: libQt5Widgets_debug.5.dylibQWidgetPrivate::repaint_sys() frame #7: libQt5Widgets_debug.5.dylib
QWidgetPrivate::syncBackingStore() 帧#8:libQt5Widgets_debug.5.dylibQWidgetWindow::handleExposeEvent() frame #9: libQt5Widgets_debug.5.dylib
QWidgetWindow::event() 帧#10:libQt5Widgets_debug.5.dylibQApplicationPrivate::notify_helper() frame #11: libQt5Widgets_debug.5.dylib
QApplication::notify() 帧#12:libQt5Core_debug.5.dylibQCoreApplication::notifyInternal2() frame #13: libQt5Gui_debug.5.dylib
QCoreApplication::sendSpontaneousEvent() 帧#14:libQt5Gui_debug.5.dylibQGuiApplicationPrivate::processExposeEvent() frame #15: libQt5Gui_debug.5.dylib
QGuiApplicationPrivate::processWindowSystemEvent() 帧#16:libQt5Gui_debug.5.dylibbool QWindowSystemInterfacePrivate::handleWindowSystemEvent<QWindowSystemInterface::SynchronousDelivery>() frame #17: libQt5Gui_debug.5.dylib
void QWindowSystemInterface::handleExposeEvent() 帧#18:libqcocoa_debug.dylibQCocoaWindow::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 frame #24: QuartzCoreCA::Context::commit_transaction(CA::Transaction*) + 319 frame #25: QuartzCore
CA::Transaction::commit() + 576 frame #26: QuartzCoreCA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 66 frame #27: CoreFoundation
CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23 frame #28: CoreFoundation__CFRunLoopDoObservers + 452 frame #29: CoreFoundation
CFRunLoopRunSpecific + 523 frame #30: HIToolboxRunCurrentEventLoopInMode + 293 frame #31: HIToolbox
ReceiveNextEventCommon + 618 frame #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)) at qcocoaeventdispatcher.mm:482 frame #36: libQt5Core_debug.5.dylib`QCoreApplication::processEvents(flags=(i = 0)) at qcoreapplication.cpp :1252
- 帧#0:libQt5Widgets_debug.5.dylib
问题是 ::processEvents 最终为 QOpenGLWidget 调用 ::paintEngine,在 ::paintGL 之外,但它完全不受我的控制。
FWIW,驱动它的事件是 QEvent::UpdateRequest。
我尝试在我的 QOpenGLWidget 继承类中重写 ::event 以在收到 QEvent::UpdateRequest 时调用 QOpenGlWidget::update,但这最终导致应用程序无响应。
我应该如何处理 ::processEvents 尝试绘制 QOpenGlWidgets?
谢谢!