Qt 学习总结

来源:互联网 发布:淘宝店招怎么加热点 编辑:程序博客网 时间:2024/05/18 17:45

Qt使用版本 2010.01 4.6.1
QtCreaterQObject 1.3.1

以下注释大多是个人注释,特别是带中文的 ^-^
个人水平有限,欢迎指正,推荐先看最下面的后记

1.全继承于QObject 拥有单根继承的优势,如3

2.F1可直接获取类的信息,库类不求人,^-^ 别忘了点More

3.inherits() metaObject()  -->JAVA里的getclass instance 对于C++里的类上转型能方便进行下转型判断了
 QTimer *timer = new QTimer;         // QTimer inherits QObject
 timer->inherits("QTimer");          // returns true
 timer->inherits("QObject");         // returns true
 timer->inherits("QAbstractButton"); // returns false

QObject *obj = new QPushButton;
 obj->metaObject()->className();             // returns "QPushButton"

 QPushButton::staticMetaObject.className();  // returns "QPushButton" // 定义名字是由objectName()

4.destroyed deleteLater 在析构函数之前调用,deleteLater 可调用多次

5.Qt的帮助文档常常有i.e. 和实例代码

6.事件处理机制相当方便
       signal and slot(信号发出与接收机制):QObject::connect 需要Q_Object
       事件机制:event()


7.*        “Qt's Property System” Qt的Property(属性)机制//广泛用于QStaticMachine
       个人认为这是一种可以极大的简化面对对象的使用与扩展的机制(不用在混乱里继续混乱了,满篇的setXX够不够混乱,再来点不同类的setXXA,setXXB怎么样,你还想用迭代来“简便

”处理吗?),并在Qt的Example里面被广泛的应用了,并且在Qt开发里也应注意并应用的该机制。
       使用了Q_PROPERTY宏(Qt对宏的应用可以说是相当精妙,Qt为了能实现在所有平台,所有C++编译器都能应用,但又不能突破或改变c++的语法,巧妙的应用了一系列宏,QObject里面

介绍了Qt的宏)在类里使用该宏定义可以改变的属性,然后在功能类里同过该宏来确定属性进行处理,极大的提高了代码的重用性。
       动态Properties(Dynamic Properties) 若Properties和Value正确则改变Value,返回True,若Properties正确Value错误则不改变Value返回False,若Properties和Value都错误,

则增加新的Properties并赋Vlaue返回False(Properties正确指名称正确,Value正确指类型正确)。
8.*       间接对象技术“Meta-Object System”这技术可以通过父类指针来操纵子类的对象,并且提供实时得到对象类名和Property,除了c++本身的dynamic_cast提供了qobject_cast进行

转型(转型失败返回0),对于熟悉OO的这部分可以看做上下转型那些,像JAVA里的getClass instance
       这部分的实现基础有3个方面 a.单根继承于QObject(单根继承都流行这种功能,并且可以用QObject指针指向任意一个对象) b.Q_OBJECT宏(可以方便使用Properties) c.间接对象

编译(“Meta-Object Compiler”,这样就与c++整合到了一起)
9. #include <Qt>直接包括了所有类库
10. new 出来的对象可以->setObjectName("name");
11. 编译较慢
12. enum Qt::GlobalColor 可以设定颜色
13. stickman 被闪电击中//例子不仅仅是例子,写那些例子的人很认真
14. QtGui部分 QPointF坐标类 QPixmap 位图类 QGraphicsPixmapItem提供位图类的类 QGraphicsScene显示图像类(JAVAcontainer)
15.The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
       QGraphicsEllipseItem provides an ellipse item
       QGraphicsLineItem provides a line item
       QGraphicsPathItem provides an arbitrary path item
       QGraphicsPixmapItem provides a pixmap item
       QGraphicsPolygonItem provides a polygon item
       QGraphicsRectItem provides a rectangular item
       QGraphicsSimpleTextItem provides a simple text label item
       QGraphicsTextItem provides an advanced text browser item
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.与QWidget类似
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
16.Hello Qt World//短小例子

abc.pro
TARGET = abc
SOURCES += main.cpp/

mani.cpp
#include <QtGui>
#include <QtCore>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QGraphicsScene scene;
    scene.addText("Hello,Qt world!");

    QGraphicsView view(&scene);
    view.show();

    return a.exec();
}
17.QStateMachine处理动画addAnimation可以使问题相当简单
       addAnimation例子:Pixmap->QGraphicsItem->QState(assignProperty addTransition)->QStateMachine
18.painter->setBrush(grad); 渐变效果,哇咔咔^0^ ~
19.*Signals and Slots 信号与接收槽 用于对象间通信。
       区别与其他回调(callback)机制,回调机制有两个主要问题:a.回调不是类型安全的,我们不能一直肯定回调用了正确的参数进行回调。b.回调和处理函数是非常强有力地联系在一

起的,因为处理函数必须知道要调用哪个回调。
       Signals and Slots里的样例图与Example
       Signal用 emit signal; 常用signal已经定义好了click
       QObject::connnect(obj1,SIGNAL(),obj2,SLOT())  <-- static
       如果一个信号绑定到了多个接收槽,那么根据connnect的先后顺序执行。
       你可以把slot设为虚函数,在联系中这种方法非常有用
       相对于回调,这种信号与接收槽的机制能稍微慢一点
       根据Qt的人测试i586-500机器上,对于一个接收槽每秒可以接收大约2,000,000个信号,两个接收槽每秒可以接受大约1,200,000个信号。换句话说就是不用担心速度问题。^-^
       SIGHAL里的函数参数一定要大于等于SOLT里面的参数,大于的情况出现于函数的参数有默认值时。
       Advanced Signals and Slots Usage例子,多同级类通过信号连接到MAP再信号连接到处理的地方

      
20.QEasingCurve 动作速度描述
21.*QObject没有拷贝构造与赋值运算,想用怎么办,用指针上下转型吧
       为什么要这么做呢?QT文档(Qt Objects: Identity vs Value)说了:是把我的对象看做一个独立的呢,还是只是个值?我觉得还是看做独立的吧。我的对象都是像人一样有身份的

啊。就算是双胞胎也是两个人,虽然看起来好像一样(对象的值一样),但确实是不同身份(Identity )的两个人。你要是还揪着复制老思想不放就不如用克隆吧,不是简单的复制,而是克

隆出一个新的个体,这样对象依然是独立的。
       PS:QObject这个根类把拷贝构造与赋值运算设置成了peivate
22.QtCreater 里面的右键里的find usage 与 find symbol很方便
23.The <QtGlobal> header file里面有一堆基本数据类型宏
24.animation是由全局的一个Timer控制进行的
25.All Overviews and HOWTOs
26.        QAction *qa=new QAction(tr("&Quit"),m);
        connect(qa, SIGNAL(triggered()), qApp, SLOT(quit()));

        mb=new QMenuBar(m);
        menu=mb->addMenu(tr("&File"));
        menu->addAction(qa);
27.uic a.ui > a.h
28.label setmovie
29.练习的代码头文件include

#include<QApplication>
#include<QWidget>
#include<QListWidget>
#include<QComboBox>
#include<QStringList>
#include<QGroupBox>
#include<QRadioButton>
#include<QtGui>
#include<QSplitter>
#include<QTabWidget>

#include<QApplication>
#include<QWidget>
#include<QPushButton>
//#include<QButtonGroup>
#include<QRadioButton>
#include<QGroupBox>
#include<QVBoxLayout>
#include<QCheckBox>
#include<QLabel>
#include<QMovie>
#include<QTableView>
#include<QPainter>

#include<QtGui>
#include<QSlider>
#include<QLCDNumber>
#include<QSpinBox>
#include<QLineEdit>
#include<QTextEdit>
#include<QTreeWidget>//代替了QListView
#include<QTreeWidgetItem>
#include<QProgressBar>


#include<QtGui>
#include<QPainter>
#include<QPrinter>
#include<QPrintDialog>
#include<QColor>
#include<QColorDialog>
#include<QFileDialog>
#include<QFontDialog>
#include<QMessageBox>
#include<QProgressDialog>
#include<QVBoxLayout>
#include<QGridLayout>
#include<QFile>

#include<QFile>
#include<QTextStream>

#include<QtGui>
#include<QtCore>
#include<QDir>
#include<QStringList>
#include<QTreeWidget>

#include<QValidator>
#include<QRegExpValidator>
#include<QDoubleValidator>
#include<QIntValidator>
#include<QMap>
#include<QMapIterator>
#include<QHash>
#include<QHashIterator>
#include<QCache> //带存储上限


#include<QPicture>
#include<QPainter>
#include<QLabel>
#include<QImage>

30.Qt Creater 选控件Layout再Morph into相应的,可以方便的做ui

31.c++Gui With Qt
32.Qt tutorials
33.下面开始看Example,顺手做的记录
Widget样例
        QDia
       Qt::FramelessWindowHint | Qt::WindowSystemMenuHint
       .qss
       俄罗斯方块
       windowflags * 各种窗口
desktop
       screenshot //截屏
              QPixmap::grabWindow(QApplication::desktop()->winId());
       systray//win7下是右下角出现消息,那个右下栏出现图标 类QSystemTrayIcon
              QApplication::setQuitOnLastWindowClosed(false);//最后一个窗口关了不会结束
              setWindowIcon(QIcon(":/heart.svg"));//窗口图标
              setContextMenu属性设置小图右键列表
              showMessage显示消息
dialogs
       findfiles//列表文件
              (QStringList)= (QDir).entryList(QStringList(fileName),QDir::Files | QDir::NoSymLinks);
draganddrop//各种拖拽
effects//各种窗口光效 炫啊
graphicsview//各种Graphic效果
ipc//QLocalSocket QLocketServer
itemviews//各种小组件拼接
           QDirModel model;
           QTreeView tree;
           tree.setModel(&model);
layouts//基本LayOut
linguist//基本语法
mainwindows//各种窗口内窗口
       QMdiArea 可用于创建窗口内小窗口
multimedia//音乐视频      
       QAudioInput* audio;QAudioFormat QAudioDeviceInfo audio->start(outputFile);//录音相关      
       QAudioOutput* audio;QAudioFormat QAudioDeviceInfo audio->start(outputFile);//放音相关      
       QVideo //被骗了,只是个放GIF的东西,但videographicsitem能转下角度
      
multitouch //多触点的例子,但里面那个老鼠的例子实在是慢点了
network//各种网络的 server client http ftp torrent tcp
       loopback//Tcp的例子,有Client Server
              class QTcpServer;
              class QTcpSocket;
       http//http的例子,下载目标网页
              class QHttp;
              class QHttpResponseHeader;
              The usage of QHttp is not recommended anymore, please use QNetworkAccessManager.//不推荐使用QHttp了
       network-chat//网络聊天室
       qftp//连接FTP服务器,并能下载
       torrent//种子下载
       threadedfortuneserver//多线程服务
       fortuneclient//客户端
opengl//各种2D 3D 如题
painting
phonon//声音
       qmusicplayer//可以播放各种音乐
              #include <phonon/audiooutput.h>
              #include <phonon/seekslider.h>
              #include <phonon/mediaobject.h>
              #include <phonon/volumeslider.h>
              #include <phonon/backendcapabilities.h>
qtconcurrent//提供高层API提供多线程
下面的还没看
XML
webkit
tools//各种
threads
statemachine
sql//现在sql基本没有基础
script//.js貌似很有用
animation//动画效果很炫

后记:
      这段后记是写在上面都写完的时候写的(2010.01.25开始学Qt,2010.02.01写本文,每天大概用12个小时),Qt是C++的一种很强力的框架,包括窗体GUI,动画,图形GUI,opengl,以及net相关,xml,sql,thread,多媒体,“QSTL”和整个QObject框架

。再说一下CSDN把Qt小版块放到移动平台是不太好的,强烈建议放到C/C++.
并且我在看<24小时Qt>那本书时,看到Qt3到Qt4的变化与改进,确实对Qt的将来发展充满期待,并且有不做手机改做软件的nokia支持,Qt是值得广大c++同志支持与使用的框架。
     下面说下我学Qt的经过:
     那天和Dahogn老师提起Qt时,老师说Qt可以看一点。然后我就下了QtSDK2010.01 288M拿来看。
     碰巧家里没网,学Qt的时候开始时特郁闷,一上来我就看的Qt官方example,要知道它可是安字母顺序排列的,一上来就是animation动画,当时我就特悲剧的从animation开始学的Qt,

当时几乎把F1按坏了,不过animation那几个帅气的例子让我对Qt有了强烈的好感,现在我也很喜欢QStateMachine这样的设计.要知道QtCreator可以用F1直接找到reference document,开始

的Signal and Slot 和QStateMachine全是看E文的。
     后来对着《24小时》学Qt,不知道CSDN上为什么老那么多人推荐那本书,那书几乎所有的例子用到的Class全都被淘汰了,我用的Qt4.6.1只能一个类一个类的慢慢看从Qt3到Qt4有什么变

化和改动,好处就是我更能确信Qt在evolute,另一方面,也练就了从reference document学习的习惯。哦,等等,也许CSDN里面的高手就是这个意思推荐这本书的。
     再后来我就开始看Qt的example,不得不说,在这个时候是学的最快的时候,多亏了前面animation(好处是看了这个什么就都不怕了)和《24》(打基础),看Example的速度相当快,

我在这再说下Example的stickman,这就是个复活节彩蛋(类似Exel里的小跑车)。Qt的Example几乎包括了所有类的使用,我强烈推荐各位看一看。
     最后我觉得上面记得33条东西对我来说最大的作用就是把我学的东西串条线,以后看一下就能想起来,大家可以拿来参考一下,欢迎指正。

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/MicroSky2813/archive/2010/02/01/5275902.aspx