linux QT5 helloword,QT helloworld 程序

1、搭建嵌入式交叉环境

a.交叉编译工具链接

b.主机交叉编译环境配置

c.Bootloder,linux内核,文件系统构建

2、简单的helloworld程序

增加执行权:chmod u+x  ./ qt-sdk-linux-x86-opensource-2010.04.bin

a.用File->New菜单来新建工程。

b.选择Qt4 Gui Application

c.输入工程名helloworld

d.软件自动添加基本的头文件

e.base class选为QDialog对话框类

f.完成工程的建立

g.工程中的所有文件都出现在列表

h.双击文件列表的dialog.ui文件

i.找到Label标签器件,拖到设计窗口上

j.双击它,并将其内容改为hello world

3、Helloworld程序的编译

在主机的\root\helloworld目录下:

生成Makefile文件

qmake –project

编译程序:make生成helloworld程序

#cp ./helloworld /nfs/app/

在目标机上:#cd ./app运行程序:#./helloworld -qws

3.目标机的运行环境

a. bootloder在/tftpboot/目录下

b. linux内核(2.6)

c.包含qt的文件系统:有两种方式下载,直接下载目标机(rootfs.img)或者用nfs方式下载

4、编译代码:先要设置它在PC里面还是在目标机中(Tools--->Options)

PC:QT4.5.3opensource,如果选了它,可以在PC机运行。

目标机:QT4.5.3,只能Build All

5、复杂的hello程序

新建GUI的hello工程,选择wedget

放一个lable三个pushbutton

选择pushbutton –>goto slot –>设置Label的text的函数:ui->lblHello->setText("Good, World");

6、信号和槽

发一个信号,会有槽(SLOT)来响应它

cmdClose这个button发clicked()     on_cmdClose_clicked()

也可以使用connect这个函数来做到

connect(ui->cmdClose, SIGNAL(clicked()),this, SLOT(on_cmdClose_clicked()))

7、标准对话框

标准的文件对话框(QFileDialog)、标准的颜色对话框(QColorDialog)、标准的字体对话框(QFontDialog)

建立standardDialog GUI工程Dialog窗口

三个pushbutton一个lineEdit一个Frame一个lineEdit

头文件:文件对话框(QFileDialog、QSring)、字体对话框(QFont、QFontDialog)

颜色对话框(QColor、QColorDialog、QPalete)

#include

#include

#include

#include

#include

#include

#include

对应的.cpp代码

文件:注意QFileDialog::getOpenFileName()、setText(s.toAscii())

QStrings=QFileDialog::getOpenFileName(this, "Open File Dialog","/", "C++ files(*.cpp);;Headfiles(*.h)");

ui->txtFile->setText(s.toAscii());

字体:注意QFontDialog:getFont(&ok)、setFont(font)

bool ok;

QFontfont = QFontDialog::getFont(&ok);

if(ok)

{

ui->txtFont->setFont(font);

}

颜色:注意QColorDialog::getColor(Qt::blue)、setAutoFillBackground(true)、setPalette(QPalette(color))

QColorcolor = QColorDialog::getColor(Qt::blue);

if(color.isValid())

{

ui->frmColor->setAutoFillBackground(true);

ui->frmColor->setPalette(QPalette(color));

}

8、标准输入框

多文本

QInputDialog::getText(this,"inputuser name!","Please input user name:", QLineEdit::Normal,nameLabel->text(),&ok);

txtName->setText(s.toAscii());

有限文本

QInputDialog::getItem(this,"Input***!", "Please select the ***:",list, 0,false,&ok);

ui->txtSex->setText(s.toAscii());

整数输入

QInputDialog::getInteger(this,"Input the Age!","Please input theage:",ageLabel->text().toInt(),0,150,1,&ok);

ui->txtAge->setText(QString(tr("%1")).arg(age));

实数输入

QInputDialog::getDouble(this,"Input the height!","Please input theheight:",175,0,230,1,&ok);

ui->txtHeight->setText(QString(tr("%1")).arg(height));

8、标准消息框

消息:提问(question)、信息(information)、警告(warning)、致命提示(critical)

头文件:QMessageBox

#include

.cpp文件

Int  ret;

Ret=QMessageBox::question()

Ret=QMessageBox::information()

Ret=QMessgeBox::warning();

Ret=QmerssageBox::critical();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值