qt常用类

发布时间 : 星期五 文章qt常用类更新完毕开始阅读

QChar 表示一个字符的类,包含于QtCore 判断:

bool isDigit() const;//判断是否是十进制数字('0'-'9') bool isLetter() const;//判断是否是字母

bool isNumber() const;//判断是否是数字,包括正负号,小数点等 bool isLetterOrNumber() const;//判断力是否是字母或数字 bool isLower() const;判断是否是小写字母 bool isUpper() const;//判断是否是大写字母 bool isNull() const;//判断是否是空字符'0' bool isPrint() const;//判断是否是可打印字符

bool isSpace() const;//判断是否是分隔符,包括空格等 转换:

char toAscii() const;//得到字符的ASCII码 QChar toLower() const;//转换成小写字母 QChar toUpper() const;转换成大写字母 ushort unicode() const;//得到Unicode编码 比较:

bool operator != (QChar c1, QChar c2);//判断c1是否不等于c2 bool operator < (QChar c1, QChar c2);// ......是否小于... bool operator <= (QChar c1, QChar c2); bool operator == (QChar c1, QChar c2); bool operator > (QChar c1, QChar c2); bool operator >= (QChar c1, QChar c2); QString 表示字符串的类,包含于QtCore

判断: bool isEmpty() const; //判断是否为空字符串 转换: 将字符串转换成数值

double toDouble(bool *ok = 0) const;//ok参数指向一个bool型变量,这个参数用于指出转换是否成功的信息. float toFloat(bool *ok = 0) const;

int toInt(bool *ok = 0, int base = 10) const;//base则有是转换成整数类型时的基,十进制就是10,八进制就是8 long toLong(bool *ok = 0, int base = 10) const;//长整型数

short toShort(bool *ok = 0, int base = 10) const;//短整型数 uint toUInt(bool *ok = 0, int base = 10) const; ulong toULong(bool *ok = 0, int base = 10) const; ushort otUShort(bool *ok = 0, int base = 10) const; QString toLower() const;//转换为小写 QString toUpper() const;//转换成大写 比较:

int compare(const QString &s1, const QString &s2,

Qt::CaseSensitivity cs = Qt::CaseSensitive );//比较两个字符串,

参数cs有两个取值, Qt::CaseInsensitive表示对大小写不敏感 Qt::CaseSensitive表示敏感 返回值的含义:大于0表示s1大于s2,等于0表示相等,小于0表示小于 查找:

bool contains(const QString &str(或QChar ch),

Qt::CaseSensitivity cs = Qt::CaseSensitive) const;//判断QString对象是否包含指定的字符串或字符 int count(const QString &str(或QChar ch),

Qt::CaseSensitivity cs = Qt::CaseSensitive) const;//得到包含某特定字符串或字符个数 int indexOf(const QString &str(或QChar ch), int from = 0,//from是查找的起点 Qt::CaseSensitivity cs = Qt::CaseSensitive) const;//得到某个特定字符串或字符位置 字符串处理:

QString &operator = (const QString &other);//复制另外一个QString对象other QString &operator = (const char *str);//复制普通字符串 QString &operator = (char ch);//复制字符

QString &operator = (QChar ch);//复制QChar类对象

以下函数可将另一个字符串或字符接在QString对象后面,形成一个整体的字符串: QString &append(const QString &str);接续QString对象 QString &append(const char *str);//接续普通字符串 QString &append(QChar ch);//接续QChar对象 !!如果把append换成prepend,则表示接在原字符串的前面

!!!!!用法:如: QString str; str.append(\就表示在str后面接上\在QString对象的任意位置插入另一个字符串或字符:

QString &insert(int position, const QString &str);插入字符串

QString &insert(int position, const QChar *pch, int size);//插入QChar数组 QString &insert(int position, QChar ch);//插入QChar对象

QString &remove(int position, int n);//移除QString对象中从位置position开始的n个字符

QString &remove(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive);//这个和下面的句子都是移除指定的字符串或字符

QString &remove(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive 替换操作: 将QString对象从position开始的n个字符替换为新内容

QString &replace(int position, int n, const QString &after);//替换QString对象 QString &replace(int position, int n, const QChar *pch, int size);//替换QChar数组 QString &replace(int position, int n, QChar after);//替换QChar对象

如果形如:QString &replace(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);则可以搜索指定的字符串或字符进行替换

清空一个QString对象的内容,使这成为空字符串: void clear();

截断QString对象,也就是去年指定位置后的所有内容: void truncate(int position); 截掉QString对象最后的若干个字符: void chop(int n);//截掉最后的n个字符 以下函数可以得到QString对象的子字符串:

QString left(int n) const;//得到左边n个字符构成的子字符串 QString right(int n) const;//得到右边n个字符构成的子字符串

QString mid(int position, int n = -1);//从中间得到子字符串,position是子字符串的起始位置,n是字符的个数,如果n为-1,则表示一直到原字符串的结尾

注意上述三个函数并不修改QString对象自身,而是返回一个临时对象以供使用

截去对象中头部和尾部的空白字符(包括空格,回车,换行,制表符等): QString trimmed() const;

这个函数不仅去掉对象头尾的空白字符,还能将中间的连续多个空白字符全部替换成一个空格: QString simplified() const; 索引: QString类也像普通的字符串一样可以根据下标得到某个位置上的字符

const QChar operator[](int(或uint) position) const;//这样对对象的取字符操作就类似于对一个字符数组的操作 统计: 以下两个成员函数都可以得到QString对象中字符的个数

int size() const; int length() const; 注意字符的个数并不一定等于字节数

QPorint: 代表一个坐标点,从属于QtCore库,可以认为是一个整型的横坐标和一个整型的纵坐标的组合 构造:

QPoint();//构造横纵坐标均为0的QPoint对象

QPoint(int x, int y);//构造横纵坐标分别为x和y的QPoint对象 属性:

通过下面两个函数可以得到QPoint对象中的横纵坐标的引用,这些引用都不是只读的,也就是说可以通过它们直接修改QPoint对象的横纵坐标

int &rx();//得到横坐标的引用 int &ry();//等到纵坐标的引用 设置QPoint对象中的横纵坐标: void setX(int x);//设置横坐标为x void setY(int y);//设置纵坐标为y

下面两个函数则是只读的,可以获得QPoint对象中的横纵坐标: int x() const;//获得横坐标 int y() const;//获得纵坐标

操作符: 支持加法和减法的复合赋值操作

QPoint &operator += (const QPoint &point);//加赋值 QPoint &operator -= (const QPoint &point);//减赋值

const QPoint operator + (const QPoint &p1, const QPoint &p2);//加法 const QPoint operator - (const QPoint &p1, const QPoint &p2);//减法 const QPoint operator - (const QPoint &point);//取负数

bool operator == (const QPoint &p1, const QPoint &p2);//判断是否相等 bool operator != (const QPoint &p1, const QPoint &p2);//判断是否不等

QSize: 代表一个矩形区域的大小,从属于QtCore库,可以认为是由一个整型的宽度和整型的高度组合而成的 构造:

QSize();//构造一个非法的QSize对象

QSize(int width, int height);//构造宽度为width,高度为height的QSize对象 属性:

int &rwidth();//得到宽度的引用,这两个引用可直接修改对象的宽度和高度 int &rheight();//得到高度的引用 void setWidth(int width);//设置宽度 void setHeight(int height);//设置高度

联系合同范文客服:xxxxx#qq.com(#替换为@)