專注電子技術(shù)學習與研究
當前位置:單片機教程網(wǎng) >> MCU設計實例 >> 瀏覽文章

QT helloworld 程序

作者:huqin   來源:本站原創(chuàng)   點擊數(shù):  更新時間:2014年03月12日   【字體:
1、 搭建嵌入式交叉環(huán)境
 

a.      交叉編譯工具鏈接

b.      主機交叉編譯環(huán)境配置

c.      Bootloder,linux內(nèi)核,文件系統(tǒng)構(gòu)建

2、 簡單的helloworld 程序

增加執(zhí)行權(quán): 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.工程中的所有文件都出現(xiàn)在列表

h.雙擊文件列表的dialog.ui文件

i.找到Label標簽器件,拖到設計窗口上

j.雙擊它,并將其內(nèi)容改為hello world

 

3、 Helloworld程序的編譯

在主機的\root\helloworld目錄下:

生成Makefile文件

qmake –project

編譯程序:make 生成helloworld 程序

#cp ./helloworld /nfs/app/

在目標機上:#cd ./app 運行程序:#./helloworld -qws

 

3.目標機的運行環(huán)境

a. bootloder /tftpboot/目錄下

b. linux內(nèi)核(2.6

c. 包含qt的文件系統(tǒng):有兩種方式下載,直接下載目標機(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的函數(shù):ui->lblHello->setText("Good, World");

6、 信號和槽

發(fā)一個信號,會有槽(SLOT)來響應它

cmdClose這個button發(fā)clicked()     on_cmdClose_clicked()

 

也可以使用connect這個函數(shù)來做到

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

7、 標準對話框

標準的文件對話框(QFileDialog)、標準的顏色對話框(QColorDialog)、標準的字體對話框(QFontDialog

建立standardDialog GUI工程  Dialog窗口

三個pushbutton 一個lineEdit 一個Frame 一個lineEdit

 

頭文件:文件對話框(QFileDialogQSring、字體對話框(QFont、QFontDialog

顏色對話框(QColor、QColorDialog、QPalete

#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());

整數(shù)輸入

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

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

實數(shù)輸入

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();

關閉窗口

相關文章