第一个qt程序:hello world!

我用的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 <QtGui/QDialog>
#include <QStandardItemModel>
#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 <QLibrary>
#include <QMessageBox>

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 <QtGui>
#include <QApplication>
#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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值