专注电子技术学习与研究
当前位置:单片机教程网 >> MCU设计实例 >> 浏览文章

QT helloworld 程序

作者:huqin   来源:本站原创   点击数:  更新时间:2014年03月12日   【字体:
1、 搭建嵌入式交叉环境
 

a.      交叉编译工具链接

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

c.      Bootloderlinux内核,文件系统构建

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 –>设置Labeltext的函数:ui->lblHello->setText("Good, World");

6、 信号和槽

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

cmdClose这个buttonclicked()     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

 

头文件:文件对话框(QFileDialogQSring、字体对话框(QFontQFontDialog

颜色对话框(QColorQColorDialogQPalete

#include<QFileDialog>

#include<QString>

#include<QFont>

#include<QFontDialog>

#include<QColor>

#include<QPalette>

#include<QColorDialog>

对应的.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,nameLa bel->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<QMessageBox>

.cpp文件

Int  ret;

Ret=QMessageBox::question()

Ret=QMessageBox::information()

Ret=QMessgeBox::warning();

Ret=QmerssageBox::critical();

关闭窗口

相关文章