Friday, April 20, 2012

Qt, OpenGL and VS2010 How To

Resources:
My guide:

First, install [1]. Next install [2]. After that, you can notice a new Qt button at the top of your VS2010 toolbar. I haven't had to use the button for anything yet but know that it's there.

Development for me using Qt and VS2010 involves using VS to program my widgets and QtDesigner to create the UI layout.

You can open up your file.ui for designing by:
  • Double clicking it in your VS2010 Solution Explorer.
  • Or by opening QtDesigner directly, finding the file.ui of your project in Explorer, and using the designers opening dialog to go to that path and open it.
I normally use the 2nd longer direct approach.

While following the Zhao Wuluo walkthrough something to look out for is the mainwidget.cpp constructor:

MainWidget::MainWidget(QWidget *parent, Qt::WFlags flags)
 : QWidget(parent, flags),
 ui(new Ui::mainwidgetClass)
{
 ui->setupUi(this);
}


That's what my constructor looks like. The auto-generated class file lacked the ui(new Ui::mainwidgetClass) constructor call and this caused my GLWidget to throw an access violation error when being constructed itself. So don't do that, construct your ui.

Thoughts on beginning Qt:

It's nice. It can seem very overwhelming at first but I believe it's a matter of how you look at it. Let go of the idea of the GUI writing itself completely through the designer. Accept the idea that the entire endeavor is regular code and brackets programming with a nice designer tool to help where it can. Also, be sure to check out the "Qt Examples and Demos" app that comes installed with your SDK because running them and checking out their documentation in the QtAssistant has helped me a lot.

I will post more as I learn more. I hope this was helpful.

1 comment:

  1. Thank you for this post. It reminded me to fix the constructor in a Qt GUI project. It usually are the little things which one keeps overlooking :)

    ReplyDelete