PDA

View Full Version : Adding slots in Designer



jamos
12th May 2006, 02:17
I'm in the proces of evaluating Qt 4.1.2 for a project that was originally written in MFC.. and I'm trying to wrap my head around things. I'm working in Visual Studio 2005; for my test I'm building a simple app with some combo boxes.

At the moment I am puzzled as to how to add slots to my window class. Designer does not seem to have any facility to add slots to a class (am I missing something?) So I have to add them by hand. However -

- If I manually add slots to my class (QtTest, derived from QMainWindow), the slots do not show up in Designer, so I can't use Designer's signal/slot facilities.

- If I were to add the slots to ui_QtTestClass, then they will be overwritten the next time I edit the form in Designer - am I correct?

I must be missing something; there's no point in having all this signal/slot support in Designer if there's no way to add slots through Designer...

jpn
12th May 2006, 06:41
At the moment I am puzzled as to how to add slots to my window class. Designer does not seem to have any facility to add slots to a class (am I missing something?) So I have to add them by hand.
Yes, you have to add them by hand.


- If I manually add slots to my class (QtTest, derived from QMainWindow), the slots do not show up in Designer, so I can't use Designer's signal/slot facilities.
True, you would have to create a custom widget plugin (http://doc.trolltech.com/4.1/designer-creating-custom-widgets.html) for the designer.


- If I were to add the slots to ui_QtTestClass, then they will be overwritten the next time I edit the form in Designer - am I correct?
Correct. You are not supposed to modify headers generated by uic.

wysota
12th May 2006, 10:42
A general approach for Qt4 is to design your user interfaces in Qt Designer and then either inherit or incorporate them in a regular C++ class derived from one of QWidget descendants and use the designed UI by calling setupUi().


class MyMainWindow : public QMainWindow, private Ui::MyMainWindow {
//...
};

or


class MyMainWindow : public QMainWindow {
//...
private:
Ui::MyMainWindow ui;
//...
};

jamos
12th May 2006, 16:52
Wow. This essentially makes Designer worthless except as a layout tool.

OK. I'll swim with that. Thanks.

wysota
12th May 2006, 17:21
It is strictly a layout tool (of course you can manage signals and slot connections there too) and not an IDE.

gfunk
19th May 2006, 00:28
Indeed, QtDesigner simply integrates into Visual Studio 2005, and piggy-backs off of Microsoft's debugger, compiler, etc. Visual Studio 2005 is still your IDE. :cool: