我需要在应用程序启动时初始化并显示OpenGL窗口,而不是像QPushButton :: clicked()这样的GUI事件。
我正在尝试在Android 4.0.4 Samsung Galaxy Tab 2上运行'openglwindow'Qt 5.1.1示例。原始项目构建并正确运行。我可以看到一个旋转的三角形。
然后我尝试通过不在main()函数中但不在'CMainWindow :: SelectSecondPage()'插槽中的事件来执行TriangleWindow.show()。成功公开事件传递但应用程序在initializeOpenGLFunctions()上的OpenGLWindow :: renderNow()函数中崩溃。
如何正确初始化和显示事件上的OpenGLWindow?
CMainWindow::CMainWindow(QWidget *parent)
: QMainWindow(parent)
{
QSurfaceFormat format;
format.setSamples(16);
m_pTriangleWindow = new TriangleWindow;
m_pTriangleWindow->setFormat(format);
m_pTriangleWindow->resize(640, 480);
m_pTriangleWindow->setPosition(5000, 5000);
m_pWidgetStack = new QStackedWidget(this);
QWidget* pFirstPage = new QWidget(m_pWidgetStack);
QPushButton* pPushButton = new QPushButton("Start Triangle window", m_pWidgetStack);
QVBoxLayout* pLayout = new QVBoxLayout;
connect(pPushButton, SIGNAL(clicked()), this, SLOT(SelectSecondPage()));
pLayout->addStretch();
pLayout->addWidget(pPushButton);
pLayout->addStretch();
pFirstPage->setLayout(pLayout);
m_pWidgetStack->addWidget(pFirstPage);
m_pSecondPage = new QWidget(m_pWidgetStack);
m_pWidgetStack->addWidget(m_pSecondPage);
setCentralWidget(m_pWidgetStack);
m_pWidgetStack->setCurrentIndex(0);
}
void CMainWindow::SelectSecondPage()
{
m_pWidgetStack->setCurrentIndex(1);
m_pTriangleWindow->show();
m_pTriangleWindow->setAnimating(true);
}
应用程序输出:
W/Qt (27127): ../src/androidjnimain.cpp:449 (jboolean startQtApplication(JNIEnv*, jobject, jstring, jstring)): Can't set environment ""
W/Qt (27127): kernel/qcoreapplication.cpp:412 (QCoreApplicationPrivate::QCoreApplicationPrivate(int&, char**, uint)): WARNING: QApplication was not created in the main() thread.
D/libEGL (27127): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
D/libEGL (27127): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
D/libEGL (27127): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
W/dalvikvm(27127): dvmFindClassByName rejecting 'org/qtproject/qt5/android/QtNativeInputConnection'
W/dalvikvm(27127): dvmFindClassByName rejecting 'org/qtproject/qt5/android/QtExtractedText'
D/Qt (27127): ../OpenGLWindow/openglwindow.cpp:118 (virtual void OpenGLWindow::exposeEvent(QExposeEvent*)): exposeEvent passed
E/libEGL (27127): eglMakeCurrent:674 error 3009 (EGL_BAD_MATCH)
W/Qt (27127): eglconvenience/qeglplatformcontext.cpp:111 (virtual bool QEGLPlatformContext::makeCurrent(QPlatformSurface*)): QEGLPlatformContext::makeCurrent: eglError: 3009, this: 0x2098190
W/Qt (27127):