QT

1.工具

assistant  帮助文档

qtconfig  QT配置工具

qmake     QT的make与项目文件智能创建工具

uic          UI界面的设计文件的编译工具

moc        moc代码创建工具

designer  UI设计工具

2.QT 的模块

qtcore

qtgui

qtnetwork

qtsvg

qtopengl

3.第一个QT程序

1.QT编程模型

2.QT程序编译过程

3.QT的项目组织

1.      QT是C++程序

2.      QT程序启动QT的环境QApplication

代码:

#include<QApplication>

#include<QDialog>

int main(int args , char **argv)

{

QApplicationapp(args , argv);

QDialog dlg;

dlg.setVisible(true);

return  app.exec();//等待子线程结束

}

编译:1.qmake–project

生成一个.pro的文件(项目配置文件)

2.qmake xxx.pro

生成makefile文件

3.make

4.执行

4.*pro文件

TEMPLATE=

:app 表明为应用程序

:lib 表明是库

SOURCES=

:cpp文件1 cpp文件2 cpp文件3

:\续行符号

HEADERS=

:h头文件

CONFIG=   影响gcc的选项

:release (-o)|debug(-g调试)

:warn_on | warn_off  (-Wall   -w   警告)

: qt  (表示qt应用,会自动加      qt库)  | opengl

:shared| static动态,静态库,只有TEMPLATE指定为lib才管用

QT=(该变量在config=qt才有意义)

:core

:gui

:network

:opengl

:svg

:xml

:sql

TARGET=

:输出的文件名(-o 输出文件名)

LIBS=用户指定库(用户自己的库)

FORMS=ui文件

程序2:

#include<QApplication>

#include<QWidget>

int main(int args,char **argv)

{

QApplicationapp(args,argv);

QWidget win;

win.setVisable(true);

returnapp.exec();

}

创建文件2:demo.pro

TEMPLATE=app

SOURCES=main.cpp

HEADERS=

CONFIG=qt release

QT=core gui

TARGET=main

直观认识QT

封装与帮助文档的使用

文档的组成部分:

1.      模块

2.类作用简单描述

3.头文件

4.父类与派生类

5.构造器/析构器()

6.共有函数

7.属性

例子:QPushButton

#include<QApplication>

#include<QWidget>

#include<QPushButton>

int main(int  args,char  **argv)

{

QApplication  app(args,argc);

QWidget  win;

win.resize(400,300);

win.move( (1024-400)/2,(768-300)/2);   //设置窗体的大小和位置

win.setVisible(true);

QPushButton  btn(&win);  //pushbutton的构造函数参数为父窗体的指针

btn.resize(100,30);        //设置button大小

btn.move(10,10);

btn.setText(“ok”);

btn.setVisible(true);

app.exec();

}

2.      乱码处理-上个程序的button中text,如果是中文会出现乱码

QT提供翻译机制

QTTextCodec类

例子:

#include<QApplication>

#include<QDialog>

#include<QPushButton>

#include<QTextCodec>

int main(int  args, char **argv)

{

QApplication  app(args,argv);

QTextCodec *codec=QTextCodec::codecForName(“gb2312”);

//设置应用程序的编码:gb2312  codecForName静态成员函数

QTextCodec::setCodecForTr(codec); //把设置的编码设置到环境中

QDialog dlg;

dlg.resize(400,300);

dlg.move((1024-400)/2,(768-300)/2);

QPushButton  btn(&dlg);

btn.resize(100,30);

btn.move(100,100);

btn.setText(QObject::tr(“确定”));  //在使用中文的地方翻译

btn.setVisible(true);

dlg.setVisible(true);

return  app.exec();

}

例子:QLineEditS

#include<QApplication>

#include<QDialog>

#include<QLineEdit>

int main(int args,char ** argv)

{

QApplication  app(args,argv);

QTextCodec *codec=QTextCodec::codecForName(“gb2312”);

QTextCodec::setCodecForTr(codec);

QDialog  dlg;

dlg.resize(400,300);

dlg.move((1024-400)/2 , (768-300)/2);

QLineEdit edit;

edit.resize(100,30);

edit.move(100,100);

edit.setVisible(true);

dlg.setVisible(true);

return app.exec();

}

3.代码组织

以窗体为基本单位的封装

案例:

登陆

QDialog

QPushButton

QLabel

QLineEdit

代码:

main.cpp

#include<QApplication>

#include<QTextCodec>

#include “logindlg.h”

int main(int  args,char **argv)

{

QApplication  app(args , argv);

QTextCodec *codec=QTextCodec::codecForName(“gb2312”);

QTextCodec::setCodecForTr(codec);

LoginDialog  dlg;

dlg.resize(400,300);

dlg.setVisible(true);

return app.exec();

}

logindlg.h

#ifndef LOGIN_DLG_H

#define LOGIN_DLG_H

#include<QDialog>

#include<QLabel>

#include<QLineEdit>

#include<QPushButton>

class LoginDialog : public QDialog

{

public:

LoginDialog(QWidget * parent=NULL);

private:

QLabel *lbluser;

QLabel *lblpass;

QLineEdit *edtuser;

QLineEdit *edtpass;

QPushButton *btnlogin;

QPushButton *btncancel;

};

#endif

Logindlg.cpp

#include “logindlg.h”

LoginDialog::LoginDialog(QWidget * parent):QDialog(parent)

{

lbluser=new  QLablel(this);

lblpass=new  QLabel(this);

this->resize(400,300);

this->move((1024-400)/2,(768-300)/2);

lbluser->resize(100,30);

lbluser->move(50,40);

lblpass->resize(100,30);

lblpass->move(50,100);

lbluser->setText(QObject::tr(“用户:”));

lblpass->setText(QObject::tr(“口令:”));

edtuser=new  QLineEdit(this);

edtpass=new  QLineEdit(this);

edtuser->resize(200,30);

edtuser->move(150,40);

edtpass->resize(200,30);

edtpass->move(150,100);

btnlogin = new QPushButton(this);

btncancel=new QPushButton(this);

btnlogin->resize(60,30);

btnlogin->move(90,210);

btncancel->resize(60,30);

btncancel->move(250,210);

btnlogin->setText(Qobject::tr(“登录”));

btncancel->setText(QObject::tr(“取消”));

}

3.      QT的界面设计器

designer 可视化编辑器

3.1. 工具视图:

用户设计区

工具箱

资源管理器

属性编辑器(ctrl+i)

动作编辑器

信号槽编辑器

对象察看器(选择对象)

3.2. 保存文件

*.ui

3.3.编辑属性

1.文本属性

2.对象名属性

3.字体属性

3.4. 编辑组件

->  <-方向

shift+方向  大小改变

ctrl+

shift+ctrl+

3.5.打开ui文件

ui是xml文本文件

3.6.使用ui文件

自动使用

手工使用

uic编译ui文件 : 例如:uic login.ui –o login.h

产生:c++头文件

Ui_对象名的类

Ui::对象名的类 Ui命名空间

以上两种使用对象的方法

类的构造器:没有(缺省构造器)

类的方法:setUi(QDialog *);

3.7.使用UI类型

Main.cpp

#include<QApplication>

#include “dlglogin.h”

int main(int args, char ** argv)

{

QApplication  app(args,argv);

DlgLogin dlg;

dlg.setVisible(true);

return app.exec();

}

dlglogin.h

#ifndef MY_LOGINDLG_H

#define MY_LOGINDLG_H

#include<QDialog>

#include “login.h”

class DlgLogin : public QDialog

{

private;

Ui_LoginDialog *ui;

public:

DlgLogin(QDialog * parent=NULL);

~DlgLogin();

}

#endif

dlglogin.cpp

#include “dlglogin.h”

DlgLogin::DlgLogin(QDialog *parent):QDialog(parent)

{

ui = new Ui_LoginDialog;

ui->setupUi(this);

}

DlgLogin::~DlgLogin()

{

delectui;

}

QT 入门 -QApplication QPushButton QDialog Ui类型的手工使用的更多相关文章

  1. Qt入门之基础篇 ( 二 ) :Qt项目建立、编译、运行和发布过程解析

    转载请注明出处:CN_Simo. 题解: 本篇内容主讲Qt应用从创建到发布的整个过程,旨在帮助读者能够快速走进Qt的世界. 本来计划是讲解Qt源码静态编译,如此的话读者可能并不能清楚地知道为何要静态编 ...

  2. Qt入门-layout布局

    开发一个图形界面应用程序,界面的布局影响到界面的美观.在设计一个界面之前,应该考虑到开发的界面可能给不用的用户使用,而用户的屏幕大小.纵横比例.分辨率可能不同,界面还可能是可缩放的,程序应该可以适应这 ...

  3. Qt入门(5)——用Qt控件创建一个电话本界面

    具体实现步骤: 一.首先用 Qt Designer 创建一个两张图的对话框,分别保存为listdialog.ui和editdialog.ui文件 要注意其中各个空间对应的名称修改好 二.新建一个Qt应 ...

  4. Qt入门(4)——Qt常见控件

    Qt提供了大量的内建控件及通用对话框可满足程序员的绝大部分要求.我们将对这些控件和对话框作一个大概的介绍. 1. QLabel 定义 QLabel* m_labelOrdered = newQLabe ...

  5. [QT]给QApplication安装事件过滤器 app.installEventFilter

    Qt的事件处理有5种级别: 1.      重写控件的事件处理函数:如重写keyPressEvent(),mousePressEvent()和paintEvent(),这是最常用的事件处理方法,我们已 ...

  6. QT入门学习

    第一个QT程序 #include<QApplication> #include<QDialog> #include<QLabel> #include<QTex ...

  7. 第15.25节 PyQt(Python+Qt)入门学习:Model/View开发实战--使用QTableView展示Excel文件内容

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 一.概述 在前面的订阅专栏<第十九章.Model/View开发:QTableView的功能及属 ...

  8. 第15.12节PyQt(Python+Qt)入门学习:可视化设计界面组件布局详解

    一.引言 在Qt Designer中,在左边部件栏的提供了界面布局相关部件,如图: 可以看到共包含有四种布局部件,分别是垂直布局(Vertical Layout).水平布局(Horizontal La ...

  9. Qt入门学习——Qt 5 帮助文档的使用

    Qt入门学习——Qt 5 帮助文档的使用 学习图形界面开发,肯定离不开帮助文档的使用,因为它不像 C 语言那样就那么几个函数接口,图形接口的接口可以用海量来形容,常用的我们可能能记住,其它的真的没有必 ...

随机推荐

  1. C语言格式化输出,空位补0,空位补空格

    char strTtimeDump[512] = ""; int a = 5; sprintf(strTtimeDump, "%.4d", a); //strT ...

  2. Java 网络编程(六) 使用无连接的数据报(UDP)进行通信

    连接地址:http://www.cnblogs.com/mengdd/archive/2013/03/10/2952673.html 使用无连接的数据报(UDP)进行通信 什么是Datagram? 数 ...

  3. 模拟JQUERY的延迟方法绑定

    模拟JQUERY的延迟方法绑定, 对于延迟方法绑定,各种语言都有不同的描述 什么回调啊,函数指针啊,委托啊,事件啊等,其实也就是那么大回事,不过用好这些特性,对于扩展和架构是非常有好处的, 好处自然就 ...

  4. SumoLogic

    SumoLogic>>>Loggly. https://diyunpeng.loggly.com/setup MonitorWare http://www.monitorware.c ...

  5. Qt之美(一):d指针/p指针详解

    Translated  by  mznewfacer   2011.11.16 首先,看了Xizhi Zhu 的这篇Qt之美(一):D指针/私有实现,对于很多批评不美的同路人,暂且不去评论,只是想支持 ...

  6. 用Mediawiki做百科网站资源大参考

    MediaWiki简易安装教程**关于mediawiki 一些好的资料: http://codex.wordpress.org.cn/Mediawiki%E5%BB%BA%E7%AB%99%E7%BB ...

  7. HDU 1997 汉诺塔VII

    题解参考博客: http://blog.csdn.net/hjd_love_zzt/article/details/9897281 #include <cstdio> ],yes; int ...

  8. Oracle 日期时间

    select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from goods t insert into goods (id,createdate) value ...

  9. leetcode_question_67 Add Binary

    Given two binary strings, return their sum (also a binary string). For example, a = "11" b ...

  10. 本地存储sessionStorage 、 localStorage 、cookie整理

    sessionStorage . localStorage .cookie 的区别 sessionStorage 和 localStorage 是HTML5 Web Storage API 提供的,可 ...