QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 694|回复: 3

帮我翻译一下

[复制链接]
发表于 2005-5-16 18:12:47 | 显示全部楼层 |阅读模式
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.
我不知是什么意思!
发表于 2005-5-16 21:03:24 | 显示全部楼层
这只是个教程,并不反映真正的开发。
你应该做的是,在Classes右击选择New Class,接着Class Generator 对话框出现,输入类名SigCreate,基类名SigCreateDlg,别忘记选上generate a QWidget-childclass,点OK。

警告,继承类不能用ui文件里相同的名字。
----------------------------------------------------------
不懂Qt,照着字面简单翻的。
回复

使用道具 举报

 楼主| 发表于 2005-5-17 10:19:25 | 显示全部楼层
谢谢版主
回复

使用道具 举报

 楼主| 发表于 2005-5-17 12:59:02 | 显示全部楼层
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.
用 .ui file 创建一个新工程类(上下文:因为在KDEVELP中新建了一个SigCreatedlg.ui,在QT中做完要做的事,保存,退出QT,回到Kdevelop中,因为Kdevelop一开始在SRC目录中就有SigCreate.cpp,SigCreate.h,main.cpp三个文件,现在要册去SigCreate.cpp,SigCreate.h这两个文件,方法是右建-册除,在弹出对话框中点先"generate a QWidget-childclassm同时在硬盘中册除")
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-6 00:42 , Processed in 0.039608 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表