I need to initialize and show OpenGL window not while application starts but by GUI event like QPushButton::clicked().

I am trying to run the ‘openglwindow’ Qt 5.1.1 example on Android 4.0.4 Samsung Galaxy Tab 2. The original project builds and runs correctly. I can see a rotating triangle.

Then I try to do TriangleWindow.show() by event not in main() function but in 'CMainWindow::SelectSecondPage()' slot. Expose event passes successfully but the application crashes in OpenGLWindow::renderNow() function on initializeOpenGLFunctions().

How can I initialize and show OpenGLWindow on event correctly?

Qt Code:
  1. CMainWindow::CMainWindow(QWidget *parent)
  2. : QMainWindow(parent)
  3. {
  4. QSurfaceFormat format;
  5. format.setSamples(16);
  6.  
  7. m_pTriangleWindow = new TriangleWindow;
  8. m_pTriangleWindow->setFormat(format);
  9.  
  10. m_pTriangleWindow->resize(640, 480);
  11. m_pTriangleWindow->setPosition(5000, 5000);
  12.  
  13. m_pWidgetStack = new QStackedWidget(this);
  14.  
  15. QWidget* pFirstPage = new QWidget(m_pWidgetStack);
  16. QPushButton* pPushButton = new QPushButton("Start Triangle window", m_pWidgetStack);
  17. QVBoxLayout* pLayout = new QVBoxLayout;
  18.  
  19. connect(pPushButton, SIGNAL(clicked()), this, SLOT(SelectSecondPage()));
  20.  
  21. pLayout->addStretch();
  22. pLayout->addWidget(pPushButton);
  23. pLayout->addStretch();
  24.  
  25. pFirstPage->setLayout(pLayout);
  26. m_pWidgetStack->addWidget(pFirstPage);
  27.  
  28. m_pSecondPage = new QWidget(m_pWidgetStack);
  29. m_pWidgetStack->addWidget(m_pSecondPage);
  30.  
  31. setCentralWidget(m_pWidgetStack);
  32. m_pWidgetStack->setCurrentIndex(0);
  33. }
  34.  
  35. CMainWindow::~CMainWindow()
  36. {
  37. m_pTriangleWindow->deleteLater();
  38. }
  39.  
  40. void CMainWindow::SelectSecondPage()
  41. {
  42. m_pWidgetStack->setCurrentIndex(1);
  43.  
  44. m_pTriangleWindow->show();
  45. m_pTriangleWindow->setAnimating(true);
  46. }
To copy to clipboard, switch view to plain text mode 

Application output:
Qt Code:
  1. Debugging starts
  2. Could not load shared library symbols for 71 libraries, e.g. /system/bin/linker.
  3. Use the "info sharedlibrary" command to see the complete listing.
  4. Do you need "set solib-search-path" or "set sysroot"?Unable to find dynamic linker breakpoint function.
  5. GDB will retry eventurally. Meanwhile, it is likely
  6. that GDB is unable to debug shared library initializers
  7. or resolve pending breakpoints after dlopen().I/Qt JAVA (27127): DEBUGGER: waiting for pong at /data/local/tmp/qt/debug-pong-org.qtproject.example.OpenGLWindow, attempt 3
  8. I/Qt JAVA (27127): DEBUGGER: got pong /data/local/tmp/qt/debug-pong-org.qtproject.example.OpenGLWindow
  9. W/Qt (27127): ../src/androidjnimain.cpp:449 (jboolean startQtApplication(JNIEnv*, jobject, jstring, jstring)): Can't set environment ""
  10. W/Qt (27127): kernel/qcoreapplication.cpp:412 (QCoreApplicationPrivate::QCoreApplicationPrivate(int&, char**, uint)): WARNING: QApplication was not created in the main() thread.
  11. D/libEGL (27127): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
  12. D/libEGL (27127): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
  13. D/libEGL (27127): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
  14. W/dalvikvm(27127): dvmFindClassByName rejecting 'org/qtproject/qt5/android/QtNativeInputConnection'
  15. W/dalvikvm(27127): dvmFindClassByName rejecting 'org/qtproject/qt5/android/QtExtractedText'
  16. D/Qt (27127): ../OpenGLWindow/openglwindow.cpp:118 (virtual void OpenGLWindow::exposeEvent(QExposeEvent*)): exposeEvent passed
  17. E/libEGL (27127): eglMakeCurrent:674 error 3009 (EGL_BAD_MATCH)
  18. W/Qt (27127): eglconvenience/qeglplatformcontext.cpp:111 (virtual bool QEGLPlatformContext::makeCurrent(QPlatformSurface*)): QEGLPlatformContext::makeCurrent: eglError: 3009, this: 0x2098190
  19. W/Qt (27127):
  20. Debugging has finished
To copy to clipboard, switch view to plain text mode