欢迎来到天天文库
浏览记录
ID:10770070
大小:169.50 KB
页数:10页
时间:2018-07-08
《qt使用指南(快速篇)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、1.首先检查系统是否已安装qt[root@localhostroot]#rpm-qqt如果出现qt-3.3.2-22.打开qtdesinger(编程->QtDesigner)3.新建一窗口(选择Widget),如图1.png4.添加一pushbutton5.在按钮上单击右键,选择Connections...6.单击New,添加signal.如图2.png7.选择EditSlots...,编辑新的slots.如图3.png8.单击NewFunction,在输入栏中输入新的slot函数名,openbtn().如图4.png9.单击ok,在刚才的窗口中选择刚才创建的新slot.如图5.pn
2、g10.保存工程.按ctrl-s,输入文件名test.ui11.进入终端窗口,进入保存test.ui的目录12.使用进行文件转换.[root@localhostexample]#uictest.ui-otest.h[root@localhostexample]#uic-impltest.htest.ui-otest.cpp13.使用编辑器建立主文件main.cpp#include#include"test.h"intmain(intargc,char**argv){QApplicationa(argc,argv);Form1w;w.show();a.c
3、onnect(&a,SIGNAL(lastWindowClosed()),&a,SLOT(quit()));returna.exec();}14.使用qmake建立工程和make文件[root@localhostexample]#qmake-project[root@localhostexample]#qmake-makefile15.打开窗口文件test.cpp,看到如下内容/******************************************************************************Formimplementationgenerate
4、dfromreadinguifile'test.ui'****Created:三11月719:55:212007**by:TheUserInterfaceCompiler($Id:qt/main.cpp3.3.2editedNov2413:47$)****WARNING!Allchangesmadeinthisfilewillbelost!****************************************************************************/#include"test.h"#include#include5、ushbutton.h>#include#include#include/**ConstructsaForm1asachildof'parent',withthe*name'name'andwidgetflagssetto'f'.*/Form1::Form1(QWidget*parent,constchar*name,WFlagsfl):QWidget(parent,name,fl){if(!name)setName("Form1");pushButton1=newQPushButton(this,"pushB6、utton1");pushButton1->setGeometry(QRect(120,100,291,51));languageChange();resize(QSize(600,480).expandedTo(minimumSizeHint()));clearWState(WState_Polished);//signalsandslotsconnectionsconnect(pushButton1,SIGNAL(clicked()),this,SLOT(openbtn()));}/**Destroystheobjectandfreesanyallocatedresources*7、/Form1::~Form1(){//noneedtodeletechildwidgets,Qtdoesitallforus}/**Setsthestringsofthesubwidgetsusingthecurrent*language.*/voidForm1::languageChange(){setCaption(tr("Form1"));pushButton1->setText(tr("pushButton1"));}voidForm1::open
5、ushbutton.h>#include#include#include/**ConstructsaForm1asachildof'parent',withthe*name'name'andwidgetflagssetto'f'.*/Form1::Form1(QWidget*parent,constchar*name,WFlagsfl):QWidget(parent,name,fl){if(!name)setName("Form1");pushButton1=newQPushButton(this,"pushB
6、utton1");pushButton1->setGeometry(QRect(120,100,291,51));languageChange();resize(QSize(600,480).expandedTo(minimumSizeHint()));clearWState(WState_Polished);//signalsandslotsconnectionsconnect(pushButton1,SIGNAL(clicked()),this,SLOT(openbtn()));}/**Destroystheobjectandfreesanyallocatedresources*
7、/Form1::~Form1(){//noneedtodeletechildwidgets,Qtdoesitallforus}/**Setsthestringsofthesubwidgetsusingthecurrent*language.*/voidForm1::languageChange(){setCaption(tr("Form1"));pushButton1->setText(tr("pushButton1"));}voidForm1::open
此文档下载收益归作者所有