Save your Qt Designer file with the name sigcreatedlg.ui and close QtDesigner. If you open this file with your favorite editor you will see that it is not C++ code but XML code. A special command line tool called uic is included with Qt Designer. This command is used to convert the .ui file into .h and .cpp files.
This is handled automatically by KDevelop. The file sigcreatedlg.ui should now appear in the KDevelop project under User Interface.
The next step is to inherit the class that KDevelop generated for you (the SigCreate class) from that new Qt Designer dialog class. In KDevelop, view the sigcreate.h file in Header/Resource Files and add
#include "sigcreatedlg.h" |
#include <kapp.h>
#include <qwidget.h>
#include <qlineedit.h>
#include <qmultilineedit.h>
#include <qcombobox.h>
#include <sigcreatedlg.h>
/** SigCreate is the base class of the project */
class SigCreate : public SigCreateDlg
{ |
Replace public QWidget by public SigCreateDlg because SigCreate inherits from SigCreateDlg.
You should have the following lines in sigcreate.h :
class SigCreate : public SigCreateDlg {
Q_OBJECT
public:
/** constructor */
SigCreate(QWidget *parent=0, const char *name=0);
/** destructor */
~SigCreate();
}; |
The file sigcreate.cpp should look like this:
#include "sigcreate.h"
SigCreate::SigCreate(QWidget *parent, const char *name) : SigCreateDlg(parent, name)
{
}
SigCreate::~SigCreate()
{
} |
You have to add manually the include files as well. In sigcreate.h, you add the three classes we used:
#include <qlineedit.h> #include <qcombobox.h> #include <qmultilineedit.h> |
![]() | As this program is intended for a tutorial, it does not reflect the "real" life of programming. What you would do after having include the .ui file is to create a new class SigCreate. To do that, right click on Classes, select New Class... and then the Class Generator dialog box appears. Enter the class name (SigCreate) and the baseclass name (SigCreateDlg). Don't forget to check the box "generate a QWidget-childclass". Then click OK. We did not follow that step as the SigCreate class is our main window. |
You can then run the project to see if everything is fine. The interface should appear but the Create! button does not work for the moment. We do that now by implementing the slot slotCreateSig().
SigCreate is a class that is derived from SigCreateDlg, we implement our slot in the SigCreate class.
You can do that by right clicking on the SigCreate class and select Add member function then go to the slot tab and fill the text fields. Or you can also edit and modify the files which I explain in details. You should have the following lines in sigcreate.cpp:
void SigCreate::slotCreateSig()
{
this->sigBox->insertLine("\n--",1);
this->sigBox->insertLine(this->nameBox->text(),2);
this->sigBox->insertLine(this->mailBox->text(),3);
this->sigBox->insertLine(this->commBox->currentText(),4);
} |
You add these lines just after:
SigCreate::~SigCreate()
{
} |
And of course you need to declare this in sigcreate.h where you should have the following:
public slots:
virtual void slotCreateSig(); |
Here is what you should get in sigcreate.h:
class SigCreate : public SigCreateDlg
{
Q_OBJECT
public:
SigCreate(QWidget* parent=0, const char *name=0);
~SigCreate();
public slots:
virtual void slotCreateSig();
}; |
You can now compile and run the program with KDevelop. Everything should be ok but if there is an error, read the output message and try to fix it.
The next chapter is a brief resume of the important steps on how to work with KDevelop and Qt Designer.
If you need any help you can either send me a mail or come and have a chat with me (irc.openprojects.net, join channel #kde-women or #kde and my nickname is annma).
You can download the source code of the SigCreate project by clicking on sigcreate-0.1.tar.gz