当QOpenGLWidget
开始在第二台显示器上运行时,我发现了一个奇怪的错误(可能是'非主'监视器的一般情况)。如果我在主显示器/屏幕上运行我的应用程序它正常工作但如果它在第二台显示器上运行它会在关闭时崩溃。我删除了尽可能多的代码来制作重现这个问题的SSCCE代码(它在下面),顺便说一下我找到了可能的原因,但它对我没有意义。
在main中我有指向widget的指针(它继承QOpenGLWidget
)。应用程序正常启动,呈现rgb三角形,但当我尝试关闭它时,我会收到:
"Unhandled exception at 0x0000000067681C6A (Qt5Cored.dll) in QtTests.exe: 0xC0000005: Access violation reading location 0x0000000000000008."
。
如果我宣布它没有'new'(就像范围内的常见对象一样),一切都很完美。它发生在我内部QOpenGLWidget
(无论多么“深”)时。我使用QWidget
,QMenuBar
,QMenu
,QAction
,QToolBar
,QPushButton
,QTabWidget
和进行了测试 QGLWidge
一切都很好,只适用于QOpenGLWidget
。你知道我做错了什么吗?如果内部包含QOpenGLWidget
,我为什么不能使用指向窗口小部件?
file "main.cpp"
#include "qttest.hpp"
#include <QApplication>
#include <QFontDatabase>
int main(int argc, char* argv[]) {
QApplication app(argc, argv);
//this is not working
OpenGLWidget* mainWindow;
mainWindow = new OpenGLWidget();
mainWindow->show();
//this is working
//OpenGLWidget mainWindow;
//mainWindow.show();
return app.exec();
}
file "qttest.hpp"
#ifndef QTTEST_HPP
#define QTTEST_HPP
#include <QPushButton>
#include <QOpenGLWidget>
#include <gl/GLU.h>
#include <gl/GL.h>
class OpenGLWidget : public QOpenGLWidget {
Q_OBJECT
public:
explicit OpenGLWidget(QWidget* parent = 0);
protected:
void initializeGL();
void paintGL();
void resizeGL(int w, int h);
private:
signals :
public slots :
};
#endif
file "openglwidget.cpp"
#include "qttest.hpp"
OpenGLWidget::OpenGLWidget(QWidget* parent) : QOpenGLWidget(parent) {
this->move(1800, 400); //set on main/other monitor
this->resize(700, 300);
}
void OpenGLWidget::initializeGL() {
glClearColor(0, 0, 0, 1);
glEnable(GL_DEPTH_TEST);
}
void OpenGLWidget::paintGL() {
glClearColor(0.1875, 0.1875, 0.1875, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(-0.5, -0.5, 0);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(0.5, -0.5, 0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(0.0, 0.5, 0);
glEnd();
}
void OpenGLWidget::resizeGL(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, (float)w / h, 0.01, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 0, 5, 0, 0, 0, 0, 1, 0);
}
如果它有助于Visual Studio中的堆栈跟踪:
Qt5Cored.dll!QScopedPointer<QObjectData,QScopedPointerDeleter<QObjectData> >::data() Line 141 C++
Qt5Cored.dll!qGetPtrHelper<QScopedPointer<QObjectData,QScopedPointerDeleter<QObjectData> > >(const QScopedPointer<QObjectData,QScopedPointerDeleter<QObjectData> > & p) Line 980 C++
Qt5Cored.dll!QObject::d_func() Line 116 C++
Qt5Cored.dll!QObject::thread() Line 1432 C++
Qt5Guid.dll!QOffscreenSurface::create() Line 183 C++
Qt5Guid.dll!QOffscreenSurface::setScreen(QScreen * newScreen) Line 328 C++
Qt5Guid.dll!QOffscreenSurface::screenDestroyed(QObject * object) Line 342 C++
Qt5Guid.dll!QOffscreenSurface::qt_static_metacall(QObject * _o, QMetaObject::Call _c, int _id, void * * _a) Line 83 C++
Qt5Cored.dll!QMetaObject::activate(QObject * sender, int signalOffset, int local_signal_index, void * * argv) Line 3742 C++
Qt5Cored.dll!QMetaObject::activate(QObject * sender, const QMetaObject * m, int local_signal_index, void * * argv) Line 3603 C++
Qt5Cored.dll!QObject::destroyed(QObject * _t1) Line 214 C++
Qt5Cored.dll!QObject::~QObject() Line 923 C++
Qt5Guid.dll!QScreen::~QScreen() Line 139 C++
[External Code]
Qt5Guid.dll!QPlatformIntegration::destroyScreen(QPlatformScreen * screen) Line 496 C++
qwindowsd.dll!QWindowsIntegration::emitDestroyScreen(QPlatformScreen * s) Line 101 C++
qwindowsd.dll!QWindowsScreenManager::clearScreens() Line 561 C++
qwindowsd.dll!QWindowsContext::~QWindowsContext() Line 357 C++
qwindowsd.dll!QWindowsIntegrationPrivate::~QWindowsIntegrationPrivate() Line 247 C++
[External Code]
qwindowsd.dll!QScopedPointerDeleter<QWindowsIntegrationPrivate>::cleanup(QWindowsIntegrationPrivate * pointer) Line 60 C++
qwindowsd.dll!QScopedPointer<QWindowsIntegrationPrivate,QScopedPointerDeleter<QWindowsIntegrationPrivate> >::~QScopedPointer<QWindowsIntegrationPrivate,QScopedPointerDeleter<QWindowsIntegrationPrivate> >() Line 108 C++
qwindowsd.dll!QWindowsIntegration::~QWindowsIntegration() Line 264 C++
qwindowsd.dll!QWindowsGdiIntegration::~QWindowsGdiIntegration() Line 62 C++
[External Code]
Qt5Guid.dll!QGuiApplicationPrivate::~QGuiApplicationPrivate() Line 1502 C++
Qt5Widgetsd.dll!QApplicationPrivate::~QApplicationPrivate() Line 199 C++
[External Code]
Qt5Cored.dll!QScopedPointerDeleter<QObjectData>::cleanup(QObjectData * pointer) Line 60 C++
Qt5Cored.dll!QScopedPointer<QObjectData,QScopedPointerDeleter<QObjectData> >::~QScopedPointer<QObjectData,QScopedPointerDeleter<QObjectData> >() Line 108 C++
Qt5Cored.dll!QObject::~QObject() Line 1049 C++
Qt5Cored.dll!QCoreApplication::~QCoreApplication() Line 854 C++
Qt5Guid.dll!QGuiApplication::~QGuiApplication() Line 629 C++
Qt5Widgetsd.dll!QApplication::~QApplication() Line 895 C++
QtTests.exe!main(int argc, char * * argv) Line 18 C++
QtTests.exe!WinMain(HINSTANCE__ * __formal, HINSTANCE__ * __formal, char * __formal, int __formal) Line 123 C++
[External Code]
我正在使用Qt插件1.2.5和Qt 5.7(msvc2013_64)在Visual Studio 2013社区中工作。