QT实验报告范本模板.docx

上传人:b****1 文档编号:14142700 上传时间:2023-06-21 格式:DOCX 页数:77 大小:404.55KB
下载 相关 举报
QT实验报告范本模板.docx_第1页
第1页 / 共77页
QT实验报告范本模板.docx_第2页
第2页 / 共77页
QT实验报告范本模板.docx_第3页
第3页 / 共77页
QT实验报告范本模板.docx_第4页
第4页 / 共77页
QT实验报告范本模板.docx_第5页
第5页 / 共77页
QT实验报告范本模板.docx_第6页
第6页 / 共77页
QT实验报告范本模板.docx_第7页
第7页 / 共77页
QT实验报告范本模板.docx_第8页
第8页 / 共77页
QT实验报告范本模板.docx_第9页
第9页 / 共77页
QT实验报告范本模板.docx_第10页
第10页 / 共77页
QT实验报告范本模板.docx_第11页
第11页 / 共77页
QT实验报告范本模板.docx_第12页
第12页 / 共77页
QT实验报告范本模板.docx_第13页
第13页 / 共77页
QT实验报告范本模板.docx_第14页
第14页 / 共77页
QT实验报告范本模板.docx_第15页
第15页 / 共77页
QT实验报告范本模板.docx_第16页
第16页 / 共77页
QT实验报告范本模板.docx_第17页
第17页 / 共77页
QT实验报告范本模板.docx_第18页
第18页 / 共77页
QT实验报告范本模板.docx_第19页
第19页 / 共77页
QT实验报告范本模板.docx_第20页
第20页 / 共77页
亲,该文档总共77页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

QT实验报告范本模板.docx

《QT实验报告范本模板.docx》由会员分享,可在线阅读,更多相关《QT实验报告范本模板.docx(77页珍藏版)》请在冰点文库上搜索。

QT实验报告范本模板.docx

QT实验报告范本模板

面向对象程序设计2

实验报告

 

专业:

计算机科学与技术

年级:

2013级

班级:

工科1班

学号:

070613047

姓名:

黄剑波

 

实验一:

线程通信:

门铃

实验时间:

实验地点:

A603

一、实验目的

1。

熟悉QT的多线程编程

2.学会使用QThread类创建线程

3.掌握使用QT事件进行跨线程通信的方法

二、实验内容

1.使用QThread类和Qt事件跨线程通信配合完成一个门铃实验。

2.门铃示例创建一个工作线程,随机发送门铃事件给GUI线程中的主人,事件中携带客人和礼物的信息,主人如果觉得客人和礼物都满意,就两眼放光,否则就假装不在.

三、实验要求

1.熟悉QT的多线程编程,了解Qt事件跨线程通信的方法

四、实验步骤

1。

使用QT应用程序向导创建GUI工程

2。

使用QTDesigner设计图形用户界面

Ø拖曳控件

Ø调整布局

Ø设置属性

Ø信号与槽映射

3.使用QTCreate编写代码

4.编译

5.构建

6.调试

五、实验源码

main.cpp

#include”doorbell.h"

#include〈QApplication〉

intmain(intargc,char*argv[])

{

QApplicationa(argc,argv);

Masterw;

w.show();

returna。

exec();

}

doorbell.h

#ifndefDOORBELL_H

#defineDOORBELL_H

#include〈QWidget〉

#include

#include〈QLabel〉

#include〈QThread>

#include

#include〈QStringList〉

#include

classBellEvent:

publicQEvent

public:

BellEvent(constQString&visitor,constQStringList&gifts);

QStringm_visitor;

QStringListm_gifts;

staticTypeeventType();

protected:

staticTypem_evType;

};

classBellThread;

classQTimer;

classRinger:

publicQObject

Q_OBJECT

public:

Ringer(BellThread*t);

publicslots:

voidonTimeout();

private:

BellThread*m_thread;

};

classBellThread:

publicQThread

friendclassRinger;

public:

BellThread(QObject*receiver);

protected:

voidrun();

private:

QPointer

};

classMaster:

publicQWidget

{

Q_OBJECT

public:

Master(QWidget*parent=0);

~Master();

protected:

boolevent(QEvent*e);

private:

QLabel*m_visitorLabel;

QLabel*m_movie;

};

#endif//DOORBELL_H

doorbell。

cpp

#include"doorbell。

h"

#include〈QDateTime>

#include〈QCoreApplication〉

#include

#include

#include

#include

QEvent:

TypeBellEvent:

:

m_evType=QEvent:

:

None;

BellEvent:

BellEvent(constQString&visitor,

constQStringList&gifts)

:

QEvent(eventType()),m_visitor(visitor)

m_gifts(gifts)

}

QEvent:

:

TypeBellEvent:

:

eventType()

{

if(m_evType==QEvent:

None)

m_evType=(QEvent:

Type)registerEventType();

returnm_evType;

//

BellThread:

BellThread(QObject*receiver)

:

m_receiver(receiver)

voidBellThread:

run()

{

qDebug()〈〈"BellThread,tid—”

currentThreadId();

QScopedPointer

exec();

}

constchar*g_vistors[5]={

"Mary","Peter”,”John",

"Haali",”Mike”

};

constchar*g_gifts[7]={

”apple","iPadmini2",”banana",

”egg","iPhone6","Bambook",

"KindleFireHD"

};

Ringer:

Ringer(BellThread*t):

m_thread(t)

{

QTimer:

:

singleShot(3000,this,SLOT(onTimeout()));

voidRinger:

onTimeout()

if(m_thread—〉m_receiver。

isNull())

{

m_thread—>quit();

return;

}

qsrand(QDateTime:

currentDateTime()。

toTime_t());

QStringListgifts;

gifts<

gifts<〈g_gifts[qrand()%7];

BellEvent*ev=newBellEvent(

g_vistors[qrand()%5],gifts);

QCoreApplication:

postEvent(

m_thread-〉m_receiver,ev);

QTimer:

singleShot((qrand()%8+2)*1000

this,SLOT(onTimeout()));

}

Master:

:

Master(QWidget*parent)

:

QWidget(parent),m_visitorLabel(newQLabel)

m_movie(newQLabel)

BellThread*t=newBellThread(this);

connect(t,SIGNAL(finished()),t,SLOT(deleteLater()));

t—>start();

QVBoxLayout*layout=newQVBoxLayout;

layout—〉addWidget(m_visitorLabel);

QMovie*gif=newQMovie(":

/eye。

gif");

m_movie->setMovie(gif);

layout->addWidget(m_movie);

m_movie-〉setVisible(false);

layout-〉addStretch

(1);

setLayout(layout);

}

Master:

:

~Master()

boolMaster:

:

event(QEvent*e)

{

if(e—〉type()==BellEvent:

:

eventType())

BellEvent*ev=(BellEvent*)e;

QStringstr=QString(”%1,gitfs[%2]”)

.arg(ev—〉m_visitor)

.arg(ev—>m_gifts。

join(”;"));

m_visitorLabel-〉setText(str);

if(ev-〉m_gifts。

contains("iPhone6”)

||ev-〉m_gifts.contains(”KindleFireHD"))

m_movie—〉setVisible(true);

m_movie—〉movie()—〉start();

}

else

{

m_movie->setVisible(false);

m_movie—>movie()—〉stop();

returntrue;

}

returnQWidget:

:

event(e);

}

doorbell。

qrc

〈RCC>

〈file〉eye.gif〈/file〉

〈/RCC>

六、实验结果与分析

七、教师评价

实验二:

高阶多线程QtConcurrent的使用:

ImageLoader

实验时间:

实验地点:

A603

一、实验目的

1。

了解高阶多线程QtConcurrent的意义

2。

掌握使用高阶多线程QtConcurrent的方法

二、实验内容

1。

Widget类重写paintEvent(),用来绘制QtConcurrent加载的图片

三、实验要求

1.开启应用程序后加载图片并显示

四、实验步骤

1.使用QT应用程序向导创建GUI工程

2。

使用QTDesigner设计图形用户界面

Ø拖曳控件

Ø调整布局

Ø设置属性

Ø信号与槽映射

3。

使用QTCreate编写代码

4.编译

5。

构建

6.调试

 

五、实验源码

main。

cpp

#include”widget。

h”

#include

#include〈QFont>

intmain(intargc,char*argv[])

QApplicationa(argc,argv);

QFontf=a.font();

f。

setPixelSize(60);

a.setFont(f);

Widgetw;

w.show();

returna。

exec();

}

widget。

h

#ifndefWIDGET_H

#defineWIDGET_H

#include

#include〈QImage〉

#include

#include〈QFutureWatcher>

classWidget:

publicQWidget

{

Q_OBJECT

public:

Widget(QWidget*parent=0);

//~Widget();

protected:

voidpaintEvent(QPaintEvent*e);

protectedslots:

voidonLoad();

voidonFinished();

private:

QFutureWatcher〈QImage〉m_watcher;

QImagem_image;

};

#endif//WIDGET_H

widget。

cpp

#include"widget.h”

#include

#include〈QFuture>

#include

#include〈QPainter〉

#include〈QTimer〉

QImageloadImage(constQString&uri)

{

QImageimage(uri);

returnimage;

Widget:

Widget(QWidget*parent)

QWidget(parent)

m_watcher(this)

connect(&m_watcher,SIGNAL(finished()),

this,SLOT(onFinished()));

QTimer:

:

singleShot(5000,this,SLOT(onLoad()));

voidWidget:

paintEvent(QPaintEvent*e)

QPainterpainter(this);

if(m_image。

isNull())

{

painter.drawText(rect(),Qt:

AlignCenter,"Loading。

");

}

else

{

painter.drawImage(rect(),m_image);

}

}

voidWidget:

onLoad()

{

QStringuri(":

/airplay.gif”);

QFuturefuture=

QtConcurrent:

run(loadImage,uri);

m_watcher。

setFuture(future);

}

voidWidget:

:

onFinished()

m_image=m_watcher。

future()。

result();

if(!

m_image.isNull())

repaint();

imageloader。

qrc

airplay。

gif〈/file>

〈/qresource〉

〈/RCC>

六、实验结果与分析

七、教师评价

实验三:

HTTP编程:

httpTestTool

实验时间:

实验地点:

A603

一、实验目的

1。

了解Qt使用QNetworkAccessManager进行http编程的基本方法

2.熟悉用QNetworkAccessManager进行http编程的注意事项

3。

熟悉QNetworkAccessManager、QNetworkRequest、QNetworkReply和QUrl这四个类,以及它们的相互关系

二、实验内容

1.使用QNetworkAccessManager、QNetworkRequest、QNetworkReply和QUrl这四个类创建一个http访问器

三、实验要求

1.实现HEAD、GET、POST、DELETE四个方法

四、实验步骤

1。

使用QT应用程序向导创建GUI工程

2.使用QTDesigner设计图形用户界面

Ø拖曳控件

Ø调整布局

Ø设置属性

Ø信号与槽映射

3。

使用QTCreate编写代码

4。

编译

5。

构建

6。

调试

五、实验源码

main。

cpp

#include”widget。

h”

#include〈QApplication>

intmain(intargc,char*argv[])

{

QApplicationa(argc,argv);

Widgetw;

w。

show();

returna.exec();

widget.h

#ifndefWIDGET_H

#defineWIDGET_H

#include

#include〈QLineEdit〉

#include

#include

#include〈QLabel〉

#include

#include

#include〈QCheckBox>

#include

#include〈QNetworkAccessManager〉

#include〈QNetworkReply>

#include

#include

classWidget:

publicQWidget

{

Q_OBJECT

public:

Widget(QWidget*parent=0);

~Widget();

protectedslots:

voidonAddHttpHeaderValue();

voidonStart();

voidonMethodChanged(constQString&method);

voidonMetaDataChanged();

voidonDownloadProgress(qint64bytesReceived,qint64bytesTotal);

voidonUploadProgress(qint64bytesSent,qint64bytesTotal);

voidonReadyRead();

voidonFinished();

protected:

voidsetupGUI();

voiddisableControls();

voidenableControls();

private:

QStringrequestString(QNetworkRequest*req);

QStringresponseString(QNetworkReply*reply);

voidresetState();

boolopenFile(boolsave,QString&errorString);

protected:

QGroupBox*m_headerValueGroup;

QLabel*m_headerKeyLabel;

QLineEdit*m_headerKeyEdit;

QLabel*m_headerValueLabel;

QLineEdit*m_headerValueEdit;

QPushButton*m_addHttpHeaderValueButton;

QGroupBox*m_stateGroup;

QTextEdit*m_stateText;

QProgressBar*m_progress;

QGroupBox*m_paramGroup;

QLabel*m_urlLabel;

QLineEdit*m_urlEdit;

QLabel*m_methodLabel;

QComboBox*m_methodCombo;

QPushButton*m_startButton;

QNetworkAccessManagerm_nam;

QNetworkReply*m_reply;

QNetworkRequest*m_request;

QStringm_strFilePath;

QFile*m_file;

};

#endif//WIDGET_H

widget.cpp

#include"widget。

h”

#include〈QGridLayout>

#include〈QVBoxLayout〉

#include

#include

#include〈QByteArray〉

#include〈QFileDialog>

#include

staticconstchar*g_ext_to_content_type[]={

"。

001","application/x-001”

”。

301”,"application/x—301”

".323","text/h323”

,”.906","application/x—906”

,”.907”,”drawing/907”

".a11","application/x-a11”

,”.acp","audio/x-mei—aac”

,".ai”,"application/postscript"

”.aif","audio/aiff”

,”。

aifc","audio/aiff"

,”.aiff”,”audio/aiff"

".anv”,”application/x-anv”

,”。

asa",”text/asa”

”.asf",”video/x-ms-asf"

”。

asp”,"text/asp”

,”。

asx”,"video/x-ms-asf”

”.au",”audio/basic"

,”.avi”,”video/avi”

"。

awf",”application/vnd。

adobe.workflow"

,"。

biz","text/xml"

,".bmp”,”application/x—bmp"

”.bot”,”application/x-bot”

,".c4t",”application/x—c4t"

,".c90",”application/x-c90”

”.cal”,"application/x—cals"

,".cat",”application/vnd。

ms-pki。

seccat"

”。

cdf”,"application/x-netcdf"

,”.cdr”,”application/x-cdr”

”。

cel",”application/x-cel”

,”。

cer”,”application/x-x509-ca-cert”

”.cg4","application/x-g4"

,”。

cgm",”application/x-cgm"

,”。

cit”,”application/x—cit"

"。

class”,”java/*"

,"。

cml",”text/xml”

".cmp",”application/x—cmp”

".cmx”,"application/x—cmx"

".cot”,”application/x—cot"

”。

conf",”text/plain”

"。

crl”,"application/pkix-crl”

”.crt”,"a

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > PPT模板 > 自然景观

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2