c++ - QMainWindow menu bar : OpenGL triggered function causes GL context issue -


i have qglwidget central widget of qmainwindow. initializes gl context , makes draw calls in paintgl function. in menubar qmainwindow, have import file button triggers function runs if qglwidget done initializegl function. import file button call should transfer vertexes of 3d object gl buffers, seems work fine.

however, when qglwidget calls paint function, receive bad access error following lines opened in debug mode :

q_assert(qopenglfunctions::isinitialized(d_ptr)); d_ptr->drawarrays(mode, first, count);     //exc_bad_access 

if trigger file importing function not import file button in menu directly qglwidget's initializegl function, fine.

what might problem? please let me know if need further information.

i found out that,

each time paint function or initializegl function runs automatically call makecurrent() function make qglwidget's gl contex current in current thread. though qmainwindow runs in same thread qglwidget, bypassing qglwidget class , therefore omitting makecurrent()function resulted opengl functions in "file import" function run @ different contexts(or null context) qglwidget.


Comments