Home > Back-end >  For help! Qt multi-window display QOpenGLWidget abnormal problem
For help! Qt multi-window display QOpenGLWidget abnormal problem

Time:12-06

scenario reduction
IDE: Qt Creator, OpenGL: 4.5, Qt: 5.9.8
I can in a window to the normal display multiple QOpenGLWidget controls (already created subclass), for example:
 
M_pVBLayout=new QVBoxLayout (this);
for(int i=0; i<10; I++) {
M_pVBLayout - & gt; AddWidget (new QOpenGLWidget (this));
}

And you can click on the button by slot dynamically add QOpenGLWidget controls, but click on the button in the slot in the open a new window, all the QOpenGLWidget controls in a new window cannot display normally, similar to an empty window,
When close the new window procedure complains, program stop in glDrawElements methods:

analysis of possible problems
See QOpenGLWidget help documentation, have so a:

According to this document, analyze the possible reason is that in a window to create a new window, two Windows with their own context, there are conflicts and context, try to solved through global Shared context, in the beginning of a program to add the following code:
 
Int main (int arg c, char * argv [])
{
QCoreApplication: : setAttribute (Qt: : AA_ShareOpenGLContexts);

QApplication a(argc, argv);

Program starts, in the first window QOpenGLWidget controls can be normal, according to the QOpenGLWidget control in the second window still don't show , but closed the second window, no errors, the program run normally,
Do you have any friends help to take a look at, thank you very much!

CodePudding user response:

Find a solution, when the window is modal window, and limit the scope of child Windows, showed normal,
This method is not applicable to the new child window
 
{
The QDialog dialog (this);
Dialog. The exec ();
}
  • Related