|
发表于 2005-5-12 01:36:25
|
显示全部楼层
我在QT designer 编了个from1.ui
uic -o form1.h form1.ui
uic -i form1.h -o form1.cpp form1.ui
把 .ui 文件转换成 QT 可以使用的 .cpp 和 .h 文件
1. #ifndef FORM1_H
2. #define FORM1_H
3. #include <qvariant.h>
4. #include <qdialog.h>
5. class QVBoxLayout;
6. class QHBoxLayout;
7. class QGridLayout;
8. class QPushButton;
9. class Form1 : public QDialog
10. {
11. Q_OBJECT
12. public:
13. Form1( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
14. ~Form1();
15. QPushButton* PushButton1;
16. };
17. #endif // FORM1_H
#################################################################
而 form1.cpp 文件如下:
1. #include "form1.h"
2. #include <qpushbutton.h>
3. #include <qlayout.h>
4. #include <qvariant.h>
5. #include <qtooltip.h>
6. #include <qwhatsthis.h>
7. /*
8. * Constructs a Form1 which is a child of 'parent', with the
9. * name 'name' and widget flags set to 'f'
10. *
11. * The dialog will by default be modeless, unless you set 'modal' to
12. * TRUE to construct a modal dialog.
13. */
14. Form1::Form1( QWidget* parent, const char* name, bool modal, WFlags fl )
15. : QDialog( parent, name, modal, fl )
16. {
17. if ( !name )
18. setName( "Form1" );
19. resize( 596, 480 );
20. setCaption( tr( "Form1" ) );
21. PushButton1 = new QPushButton( this, "PushButton1" );
22. PushButton1->setGeometry( QRect( 130, 160, 161, 71 ) );
23. PushButton1->setText( tr( "Exit" ) );
24. // signals and slots connections
25. connect( PushButton1, SIGNAL( clicked() ), PushButton1, SLOT( setFocus() ) );
26. }
27. /*
28. * Destroys the object and frees any allocated resources
29. */
30. Form1::~Form1()
31. {
32. // no need to delete child widgets, Qt does it all for us
33. }
############################
用VI 写了个非常的简单的main.cpp非常的简单的
#include "form1.h"
#include <kapp.h>
int main(int argc, char **argv)
{
KApplication app(argc, argv, "Form1"); //KDE 是建立在QT的基础上得所以KApplication
//所以kapp.h实际上包含了qapplication.h
Form1 *form1=new Form1();
form1->show();
app.setMainWidget(form1);
return(app.exec());
}
################################
打开 Kdevelop 以後,选择 项目->新建, KDE2-Normal
把其中的选项都除去没有选中!就一直下一步了!!
之后在Kdevelop的 项目->添加现存文件.然後把刚uic出来的form1.cpp form1.h 和 main.cpp 加入,
按F9make时出面了:
gmake all-recursive
gmake[1]: Entering directory `/root/myqt/hobby'
Making all in hobby
gmake[2]: Entering directory `/root/myqt/hobby/hobby'
Makefile:403: .deps/form1.Po: 没有那个文件或目录
Makefile:404: .deps/main.Po: 没有那个文件或目录
gmake[2]: *** No rule to make target `.deps/main.Po'. Stop.
gmake[2]: Leaving directory `/root/myqt/hobby/hobby'
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory `/root/myqt/hobby'
gmake: *** [all] Error 2
*** 失败 ***
请高手指点!! |
|