一、字符串类QString:

1.操作字符串:

(1)“+”、“+=”操作符:

例:QString str=“Hello,”;

    str=str+“world!”;

    str+=“We come!”; //str=“Hello,world!We come!”

(2)QString::append()函数:(和“+=”操作符有同样功能)

例:QString str1 =“Hello,”;

    QString str2 =“world!”;

    str1.append(str2);  //str1=“Hello,world!”

(3)QString ::sprintf()函数:

例:str.sprintf(“%s %s”,“Welcome ”,“to you!”);//str=“Welcome to you!”

(4)QString::arg()函数:

例:str=QString(“%1 was born in %2”.arg(“I”).arg(“1995”));//str=“I was born in 1995”

(5)QString其它组合字符串:

①insert()函数:在特定位置插入另一个字符串

②prepend()函数:在开头插入另一个字符串

③replace()函数:可以用特定字符串代替原字符串

(6)QString::trimmed()函数:移除字符串两端的空白字符

QString::simplified()函数:作用和trimmed一样 ,并可以使多个空白字符用单个字符“”代替。

2.查询字符串数据:

(1)QString::startsWith(字符串,大小写敏感度):判断一个字符串是否以某个字符串开头。

(2)QString::endsWith(字符串,大小写敏感度):判断一个字符串是否以某个字符串结束。

(3)QString::contains(字符串,大小写敏感度):判断一个字符串是否包含某个字符串。

(4)比较两个字符串长度大小:

①operator比较符(const QString &)

②localeAwareCompare(const QString&,const QString&):前者小于后者,返回负数,反之。

③compare(const QString&,const QString&,QT::Casesensitivity):与localeAwareCompare()返回值类似,但可以进行大小写比较。

3.字符串转换:

(1)QString::toInt():将字符串转换为整型数值。类似的有:toDouble()、toFloat()等等。

4.容器类:

(1)QList:

①如果T是一个指针类型或指针大小的基本类型,QList<T>会直接将其存在数组中。

②如果Qlist<T>存储对象的指针,则该指针指向实际存储的对象。

(2)QLinkedList:QLinkedList<T>是一个链式列表,不能使用下标,只能使用迭代器访问其数组项。

(3)QVector:QVector<T>在内存中存储给定数据类型T的一组数值。既可以使用下标访问数据项,也可以使用迭代器访问数据项。

④QMap类:QMap<Key,T>提供了一个从类型为Key的键到类型T的值得映射。

⑤QHash类:QHash<Key,T>与QMap有几乎相同的API(应用程序编辑窗口)。其可以以任意顺序组织它的数据。

二、控件:(选取几个重要的和常用的)

1.按钮组:①Push Button 按钮②Radio Button 单选按钮

2.输入控件组:①Line Edit 行编辑②Time Eidt 时间编辑

例子:获取本地时间:

QLabel*datalabel =new QLabel();

QDateTime*datatime=new QDataTime(QDateTime::currentDateTime());

datalabel->setText(dataTime->date().toString());

datalabel ->show();

3.显示控件组:①Label 标签②QWebView Web视图

4.空间间隔组:①Horizontal Spacer 水平间隔② Vertical Spacer 垂直间隔

5.布局管理组:①Vertical Layout 垂直布局②Grid Layout 网格布局

布局例子:QLabel *label =new QLabel(tr("Name:"));

QLineEdit * lineEdit =new QLineEdit();

QHBoxLayout *layout =new QHBoxLayout();

layout->addWidget(label);

layout->addWidget(lineEdit);

layout->setLayout(layout);

6.容器组①Group Box 组框

7.项目视图组:①List View清单视图②Tree View 树视图

8.项目控件组:①List Widget 清单控件②Tree Widget 树控件③Table Widget 表控件