| Home | |
![]() | Writing code |
| Prev | Creating dialog boxes in KMyMoney | Next |
Your code to process form actions should be included in source files named <kn>dlg.h/.cpp, in the same folder as the .ui file. You can view these for many examples of how to code. Some requirements are:
This should start with definitions similar to the following
#ifndef <KN>DLG_H #define <KN>DLG_H
#include "../dialogs/<kn>dlgdecl.h"
class <KN>Dlg : public <KN>DlgDecl {
Q_OBJECT
public:
<KN>Dlg(QWidget *parent = 0, const char *name = 0);
~<KN>Dlg();
The first two lines are the standard include stoppers, to avoid multiple inclusion of the class data.
The include file will have been generated by the Qt UIC (User Interface Compiler) from the .ui file for the dialog, under control of the make process.
The Q_OBJECT macro (written without any punctuation) will cause the Qt MOC (Meta Object Compiler) to generate additional object code and files which are necessary to support the signal/slot functionality (among other things).
The class declaration must also include a
public slots:
and
signals:
sections if you plan to use the signal/slot mechanism. See the Qt documentation about signals and slots. An example would be slotHelp() which will be connected to the clicked() signal of the help button of your dialog in the constructor of your dialog.
Terminate the file with
#endif
to close off the include stoppers.
First, don't forget to have #include directives for Qt headers for any widgets you are going to reference.
In the constructor function, connect all signals to their appropriate slots using the Qt connect() call.
Then the easy bit; write your code.
Finally, terminate the source file with the following
#include "<KN>dlg.moc"
This is one of the files generated by the Qt MOC (Meta Object Compiler) during the make process; if you finish up with 'vtable' errors, it's probably because you forgot to include this.
| Prev: | Home | Next: |
| Designing the dialog | Up | Updating the Makefile |