Chinaunix首页 | 论坛 | 博客
  • 博客访问: 24132
  • 博文数量: 6
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 55
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-31 23:56
文章分类
文章存档

2009年(6)

我的朋友

分类: 嵌入式

2009-09-10 21:47:43

我用的qt4+Eclipse开发,我来说一下步骤吧,供你参考:
(ps:使用Eclipse制作界面和编程、编译)
现在,我要建立一个对话框,对话框内只有一个按钮(pushButton),点击按钮会弹出一个MessageBox.步骤如下:
1、新建一个文件夹test1,打开Eclipse制作好界面
2、在test1文件夹内添加3个文件,分别为test1.h,test1.cpp,main.cpp,在test1.h添加如下代码:
#ifndef TEST1_H
#define TEST1_H

#include 
#include 
#include "ui_test3.h"

class test : public QDialog
{
Q_OBJECT

public:
test(QWidget *parent = 0);
~test();
private:
Ui_Dialog ui;
private slots:
void on_pushButton_clicked();
};

#endif
在test1.cpp中添加如下代码:
#include "test3.h"
#include 
#include 

test::test(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
}

test::~test()
{

}

void test::on_pushButton_clicked()
{
QMessageBox::information(this,tr("hello"),tr("Hello world!"));
}
在main.cpp中添加如下代码:
#include 
#include 
#include "test1.h"

int main(int argc, char *argv[])
{
QApplication app(argc,argv);
test *dialog = new test;
dialog->show();
return app.exec();
}
3、使用Eclipse进行编译、运行,就OK了。
需要知道qt+Eclipse的环境,请看我另外的一篇文章:
http://blog.chinaunix.net/u3/103745/showart_2048620.html


vc里面给一个按钮添加事件只需要通过双击按钮就可以了,但是这里不一样,通常情况下有两种方法。1、按照一定的命名规则为一个函数取名字,规则如下:on_name_singal,比如要为pushButton_2添加一个事件,只需要将相应函数命名为 on_pushButton_2_clicked();就可以了.2、使用connect连接控件和相应的函数,比如上面的例子我们可以在构造函数里添加 connect(pushButton,SIGNAL()clicked(),this,SLOT(hahaha()));
(ps:先把on_pushButton_clicked()函数改名为hahaha)
阅读(603) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~