|
Chapter 7. Generating the source (alternate)
Without using the KDevelop subclassing capability
Step 1 - Be sure you saved your form with the name sigcreatedlg.ui and close Qt Designer. 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.
Note
If for some reason KDevelop does not generate the .h and .cpp files from sigcreatedlg.ui, here are the two commands you can use in konsole to do it manually, in ~/sigcreate/src:
uic -o sigcreatedlg.h sigcreatedlg.ui
uic -o sigcreatedlg.cpp -i sigcreatedlg.h sigcreatedlg.ui
Step 2 - You now have 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 by selecting it in the File Selector and add
#include "sigcreatedlg.h"
at the top of the sigcreate.h file, with all the headers you need.
#include <kapplication.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 KMainWindow 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()
{
}
Step 3 - You have to add manually the include files as well. In sigcreate.h, you add the three following headers, one for each of the class we used:
#include <qlineedit.h>
#include <qcombobox.h>
#include <qmultilineedit.h>
Step 4 - Comment out a few lines in the main.cpp file:
/* if (app.isRestored())
{
RESTORE(SigCreate);
}
else*/
as the project was intended to be based on a KMainWindow which offers a lot of facilities.
Note
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.
Warning
The derived class cannot be named as the .ui file. From the .ui file, a .cpp and a .h files are automatically generated so you must have different names. You can indicate a interface file by having dlg in its name. The derived .ui class can be named for example mainWindowDlg.
其中的
Note
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.
Warning
The derived class cannot be named as the .ui file. From the .ui file, a .cpp and a .h files are automatically generated so you must have different names. You can indicate a interface file by having dlg in its name. The derived .ui class can be named for example mainWindowDlg.
我不知是什么意思! |
|