[Qt-interest] QMainWindow and QGL.

Karol Krizka kkrizka at gmail.com
Wed May 13 00:31:21 CEST 2009


On Tue, May 12, 2009 at 2:59 PM, Freak . <mentalcodes at gmail.com> wrote:
> Hi, I'm new to C++ and Qt development. (long time listener, first time
> poster)
> I'm using the LGPL license attempting some personal development, using
> MSVC2008 under x64. I have compiled the libs for x64 and I can compile
> examples without any issues.
>
> A very simple Noob question: I'm trying just to make an OGL example with a
> single QMainWindow and the Central Widget set to QGLWidget. I'm trying to
> workout how to place the QGL Widget as the Central Widget? I have looked
> through the documentation and examples, (which are great BTW) but am unable
> to see how i set it.
>
> I have read about these below and i assume I'm on the right path but am
> unable to work out where or how or where i implement this for my GLWidget
> class.
>
> QWidget * QMainWindow::centralWidget () const
>
> void QMainWindow::setCentralWidget ( QWidget * widget )
>
> setCentralWidget(
>
> So i guess the above commands are what i want, but implementing it seems to
> make me run around in circles.... Am i on the right path? Individually i
> have a main.cpp, mainwindow.cpp and GLWidget.cpp  with appropriate headers,
> I can compile the application so either window works, but i cannot get Main
> to display GLWidget.
>
> Any help on the matter would be good, meanwhile i have many books, example
> and docs to try and read...
>
Try:
int main(int argc,char* argv[])
{
  QApplication app(argc,argv);

  QMainWindow window;
  QGLWidget oglwdg;
  window.setCentralWidget(&oglwdg);
  window.show();
  return app.exec();
}

I don't have access to a computer with Qt right now, so I'm not 100%
sure that the above code works (or if it even compiles), but that is
the general idea.

--
Cheers,
Karol Krizka
http://www.krizka.net



More information about the Qt-interest-old mailing list