PDA

View Full Version : Using Designer output in VS 2008 Standard



rtc1
29th November 2009, 05:12
I just created my first non-hand-coded Qt GUI using Designer but I don't know how to use the result in my other QDialog derived C++ class. I created a complex widget using Designer and this resulted in a VisControls.ui file. After it compiled, I had ui_VisControls.h which contains the UI code with 2 classes: Ui_VisControls and an emty class Ui::VisControls : Ui_VisControls.

I tried:

#include "GeneratedFiles/ui_VisControls.h"
using Ui;
...
VisControls *w = new VisControls();
w->Show();

Then got the compiler error 'Show' is not a member of Ui::VisControls. This makes sense because nowhere in the generated files that I can find is there a " : QWidget" making the class I created derive from QWidget. Neither Ui_VisControls or Ui::VisControls derives from QWidget. Since the ui_VisControls.h file is regenerated when I compile, I can't very well add " : QWidget" there.

All I am looking for is how to take the output of Designer and then instantiate QWidget-derived classes. That is, how do I plug the results of Designer into my applications?

I've been using Qt in Visual Studio 2008 Standard for a couple of months with no problems.

I must be making a simple mistake because the property editor in Designer has QWidget attributes. I saw no place in Designer where I could specify the base class when creating my new Form.

Sorry for the dumb question! Below is the code where I want to display my form. The .ui and generated .h files are too large to attach in this forum so I included excerpts below.

Thank you in advance. I have looked at this problem for hours but to no avail.

Rick

------------------------------------------------

ui_VisControls.h excerpt:




#ifndef UI_VISCONTROLS_H
#define UI_VISCONTROLS_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDoubleSpinBox>
#include <QtGui/QGroupBox>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QPushButton>
#include <QtGui/QSlider>
#include <QtGui/QSpinBox>
#include <QtGui/QWidget>

QT_BEGIN_NAMESPACE

class Ui_VisControls
{
public:
QGroupBox *groupBox;
QSlider *cameraPositionXSlider;
QSlider *cameraPositionXYSlider;
QSlider *cameraPositionZSlider;
< many more lines... >



------------------------------------------------

Here is an excerpt from the .ui file:



<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>VisControls</class>
<widget class="QWidget" name="VisControls">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>281</width>
<height>761</height>
</rect>
</property>
<property name="windowTitle">
<string>VisControls</string>
</property>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>261</width>
<height>81</height>
</rect>
</property>
<property name="title">
<string> Camera Position </string>
</property>
<widget class="QSlider" name="cameraPositionXSlider">
<property name="geometry">
<rect>
<x>30</x>
< many more lines >



------------------------------------------------

This is the place where I attempted to use the Designer-generated class:




#include "GeneratedFiles/ui_VisControls.h"
using namespace Ui;
...
void OpenGLDlg3::test1ButtonPressed() {
VisControls *w = new VisControls();
w->Show();
emit test1();
}

squidge
29th November 2009, 11:03
If you look into the ui_*.h file, you should see a method setupui(). You should call that, giving it the parent widget to populate with controls.

You could also drop a qwidget on the main form with designer, and then promote it to your new class.

rtc1
29th November 2009, 17:22
Thanks! After reading your posting, I Googled setupui and found this link which explains things very well:

http://qt.nokia.com/doc/4.0/porting4-designer.html

Thanks again!