PDA

View Full Version : Generating header files from ui files with uic



Mannion
30th September 2010, 12:10
Hi there,

I'm just following examples from Jasmin Blanchette's book "C++ GUI Programming with Qt 4" Second Edition, which seems to be very good so far. The only area I'm having any difficulty with is using Qt Designer to generate C++ header files.

In the gotocelldialog example, from Chapter 2, when I run qmake -project & qmake gotocell.pro the ui_gotocelldialog.h file is not created. I've searched on my system and it didn't appear in any other path either.

I am running the latest 2010.05 realease of the Qt SDK on Windows XP SP3 under the LGPL license (although my license knowledge is somewhat limited)

I think my main.cpp file is the same as the example


#include <QApplication>
#include <QDialog>
#include "ui_gotocelldialog.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);

Ui::GoToCellDialog ui;
QDialog *dialog = new QDialog;
ui.setupUi(dialog);
dialog->show();

return app.exec();
}

The example files show a ui file as follows:


<ui version="4.0" >
<class>GoToCellDialog</class>
<widget class="QWidget" name="GoToCellDialog" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>190</width>
<height>94</height>
</rect>
</property>
<property name="windowTitle" >
<string>Go to Cell</string>
</property>
<layout class="QVBoxLayout" >
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="label" >
<property name="text" >
<string>&amp;Cell Location:</string>
</property>
<property name="buddy" >
<cstring>lineEdit</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit" />
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" >
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okButton" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" >
<string>OK</string>
</property>
<property name="default" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton" >
<property name="text" >
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<tabstops>
<tabstop>lineEdit</tabstop>
<tabstop>okButton</tabstop>
<tabstop>cancelButton</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

my ui file is as follows


<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GoToCellDialog</class>
<widget class="QWidget" name="GoToCellDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>250</width>
<height>71</height>
</rect>
</property>
<property name="windowTitle">
<string>Go to Cell</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&amp;Cell Location:</string>
</property>
<property name="buddy">
<cstring>lineEdit</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>68</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>OK</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<tabstops>
<tabstop>lineEdit</tabstop>
<tabstop>okButton</tabstop>
<tabstop>cancelButton</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

There seems to be something going on with


1.<?xml version="1.0" encoding="UTF-8"?>

Any ideas why Qt Designer is generating this difference, or if it is an issue?

Mannion
30th September 2010, 12:22
Ahhh I see. Sorry for the newbie comment. The header file is generated after running make. This certainly isn't clear in the book though.

Anyway at least it got me to post something. Hopefully my next post will be more worthwhile.

Zlatomir
30th September 2010, 12:26
And there are errors with that include when you run nmake, or mingw32-make if you use the SDK, which comes with mingw compiler?
EDIT: too late :o