PDA

View Full Version : Multiple forms inside a project



paul23
27th February 2012, 20:23
Hi there, First of all I'm using visual studio 2010 with the QT plugin.

In my application I wish to use different forms (duh) when user click buttons. Now I created 2 files with the designer: "RoomStd.ui" & "ResourceCompare.ui". In visual studio I right click the tree and add "existing component" and add those 2 files to the project tree (under forms).


The moc/uic tool correctly generates ui_RoomStd.h & ui_ResourceCompare.ui. Which I use in my classes like:

#include "ui_RoomStd.h"
namespace MW {
class RoomStdDialog : public TreeCompareDialog {
Q_OBJECT
public:
Ui::Form ui;
};
}

(And similar for ResourceCompare).

All fine and good: however there pops up a problem now, when compiling I get the following error:

1>d:\my documents\visual studio 2010\Projects\GMOrganizer_GUI\GMOrganizer_GUI\Gene ratedFiles\ui_ResourceCompare.h(26): error C2011: 'Ui_Form' : 'class' type redefinition
Looking into both header files (ui_ResourceCompare.h & ui_RoomStd.h) I see the culprit; Both headers use the "class Ui_Form" as main class for the (modal) window. Can't I use multiple designed modal windows in my application or something?

steno
27th February 2012, 20:59
You can use multiple ui files in one project. In creator, make sure to differentiate the object names of the top level widgets. That is used to compile the name of the class.

paul23
27th February 2012, 22:07
I'm not using the creator - just the visual studio add in

steno
28th February 2012, 00:07
Sorry I meant designer. Click on the top level widget, and there is a property called ObjectName. The names of the top level widgets in different files have to be unique. The default is form.