I am about to complete my first ever game. I have used Qt for windowing and OpenGL for actual game logic. I am confused about .. things which are related to design so according to FAQ, these kinda questions are valid. So from the past experience, people who are more interested in deciding what others should ask here and what should not, are taken care of.

(1) With Qt, How to go about connecting pieces? The very first thing comes to my mind is ==> create a screen having few images(carttons) on it, start some music loop, give few buttons; and upon button click event, create OpenGL context and handle the control to it.

But I doubt if this is the way it is done. I tried reading few forum posts but some were either not relevant and others were too complex

(2) And about exiting the game. Is it wise to have OpenGL context kept as it is; and upon reply, use that context to restart a game? Or will it be harmful in any way?

I understand that these questions would not have definite answers, but others suggestions, who have experienced and did these things, can definitely help me in going ahead.

  • 2
    \$\begingroup\$ Welcome to the crazy world of game development. \$\endgroup\$ Mar 28, 2013 at 13:36

1 Answer 1


You need to get some more QT experience and everything will all make sense. What you're trying to do is all very basic QT programming.

There's nothing different from a "regular" QT app pulling up a new window (or show()+raise()) and an OpenGL window is just another QMainWindow with a widget, or whatever you're using.

You don't "hand the control" to the new window, if it's the active window it has control when you raise() it. Your windows are running inside the QT framework, which is entirely event driven, you do not have a "main loop" of your own. Until you get some more QT experience, or you are experienced with other event-driven frameworks you're going to have a hard time designing your code.

The basic structure and flow of a full QT app is that you create a main window for the app itself, this runs the exec() which gets inputs via events from the GUI. Based on those events you then new MyNextWindow and show()+raise() to activate it. That window does its thing with inputs and events, and thus the circle of life is complete.

Since an OpenGL context is tied to a widget in a window you're not controlling that separately, whatever window has that widget controls the lifetime of the context. It's not harmful if you just hide() and show() that window, as far as I know. That's the extent of what QT does with OpenGL for you, everything else you are responsible for in the Paint method.

  • \$\begingroup\$ thanks for the reply.. you meant Qt in your instead of QT..! and yes you are money about event driven architecture.. I am indeed trying XWindow and Win32 also.. \$\endgroup\$
    – Adorn
    Mar 31, 2013 at 20:24

Not the answer you're looking for? Browse other questions tagged .