網(wǎng)上有很多關(guān)于pos機(jī)消費(fèi)類型c,Qt——常用數(shù)據(jù)類型的知識,也有很多人為大家解答關(guān)于pos機(jī)消費(fèi)類型c的問題,今天pos機(jī)之家(www.afbey.com)為大家整理了關(guān)于這方面的知識,讓我們一起來看下吧!
本文目錄一覽:
pos機(jī)消費(fèi)類型c
1. 基礎(chǔ)類型因?yàn)镼T是一個C++框架, 因此C++中所有的語法和數(shù)據(jù)類型在Qt中都是被支持的, 但是Qt中也定義了一些屬于自己的數(shù)據(jù)類型, 下邊給大家介紹一下這些基礎(chǔ)的數(shù)類型。
QT基本數(shù)據(jù)類型定義在#include <QtGlobal> 中,QT基本數(shù)據(jù)類型有:
類型名稱
注釋
備注
qint8
signed char
有符號8位數(shù)據(jù)
qint16
signed short
16位數(shù)據(jù)類型
qint32
signed short
32位有符號數(shù)據(jù)類型
qint64
long long int 或(__int64)
64位有符號數(shù)據(jù)類型,Windows中定義為__int64
qintptr
qint32 或 qint64
指針類型 根據(jù)系統(tǒng)類型不同而不同,32位系統(tǒng)為qint32、64位系統(tǒng)為qint64
qlonglong
long long int 或(__int64)
Windows中定義為__int64
qptrdiff
qint32 或 qint64
根據(jù)系統(tǒng)類型不同而不同,32位系統(tǒng)為qint32、64位系統(tǒng)為qint64
qreal
double 或 float
除非配置了-qreal float選項(xiàng),否則默認(rèn)為double
quint8
unsigned char
無符號8位數(shù)據(jù)類型
quint16
unsigned short
無符號16位數(shù)據(jù)類型
quint32
unsigned int
無符號32位數(shù)據(jù)類型
quint64
unsigned long long int 或 (unsigned __int64)
無符號64比特數(shù)據(jù)類型,Windows中定義為unsigned __int64
quintptr
quint32 或 quint64
根據(jù)系統(tǒng)類型不同而不同,32位系統(tǒng)為quint32、64位系統(tǒng)為quint64
qulonglong
unsigned long long int 或 (unsigned __int64)
Windows中定義為__int64
uchar
unsigned char
無符號字符類型
uint
unsigned int
無符號整型
ulong
unsigned long
無符號長整型
ushort
unsigned short
無符號短整型
qsizetype
size_t
2. log輸出在Qt中進(jìn)行l(wèi)og輸出, 一般不使用c中的printf, 也不是使用C++中的cout, Qt框架提供了專門用于日志輸出的類, 頭文件名為 QDebug。
【領(lǐng)更多QT學(xué)習(xí)資料,點(diǎn)擊下方鏈接免費(fèi)領(lǐng)取↓↓,先碼住不迷路~】
點(diǎn)擊→領(lǐng)Qt開發(fā)必備技術(shù)棧學(xué)習(xí)路線+資料
基本分類
qDebug:調(diào)試信息提示qInfo :輸出信息qWarning :一般的警告提示qCritical :嚴(yán)重的錯誤提示qFatal :致命錯誤提示,會直接中斷程序C風(fēng)格輸出
qDebug("我是%s,今年%d歲了~","maye",20);qInfo("maye%d",666);qWarning("hello %s","warning");qCritical("helo %s","critical");qFatal("hello %s","qFatal"); //致命錯誤會直接中斷程序
C++風(fēng)格
qDebug()<<"好帥"<<endl;qInfo()<<"qInfo"<<endl;qWarning()<<"qWarnning"<<endl;qCritical()<<"qCritical"<<endl;#qFatal()<<"qFatal"<<endl; //致命錯誤不能用<<輸出3. 字符串類型
C => char*
C++ => std::string
Qt => QByteArray, QString
3.1 QByteArray在Qt中QByteArray可以看做是C語言中 char*的升級版本。我們在使用這種類型的時候可通過這個類的構(gòu)造函數(shù)申請一塊動態(tài)內(nèi)存,用于存儲我們需要處理的字符串?dāng)?shù)據(jù)。
下面給大家介紹一下這個類中常用的一些API函數(shù),大家要養(yǎng)成遇到問題主動查詢幫助文檔的好習(xí)慣
構(gòu)造函數(shù)// 構(gòu)造空對象, 里邊沒有數(shù)據(jù)QByteArray::QByteArray();// 將data中的size個字符進(jìn)行構(gòu)造, 得到一個字節(jié)數(shù)組對象// 如果 size==-1 函數(shù)內(nèi)部自動計(jì)算字符串長度, 計(jì)算方式為: strlen(data)QByteArray::QByteArray(const char *data, int size = -1);// 構(gòu)造一個長度為size個字節(jié), 并且每個字節(jié)值都為ch的字節(jié)數(shù)組QByteArray::QByteArray(int size, char ch);
數(shù)據(jù)操作
// 其他重載的同名函數(shù)可參考Qt幫助文檔, 此處略QByteArray &QByteArray::append(const QByteArray &ba);void QByteArray::push_back(const QByteArray &other);// 其他重載的同名函數(shù)可參考Qt幫助文檔, 此處略QByteArray &QByteArray::prepend(const QByteArray &ba);void QByteArray::push_front(const QByteArray &other);// 插入數(shù)據(jù), 將ba插入到數(shù)組第 i 個字節(jié)的位置(從0開始)// 其他重載的同名函數(shù)可參考Qt幫助文檔, 此處略QByteArray &QByteArray::insert(int i, const QByteArray &ba);// 刪除數(shù)據(jù)// 從大字符串中刪除len個字符, 從第pos個字符的位置開始刪除QByteArray &QByteArray::remove(int pos, int len);// 從字符數(shù)組的尾部刪除 n 個字節(jié)void QByteArray::chop(int n);// 從字節(jié)數(shù)組的 pos 位置將數(shù)組截斷 (前邊部分留下, 后邊部分被刪除)void QByteArray::truncate(int pos);// 將對象中的數(shù)據(jù)清空, 使其為nullvoid QByteArray::clear();// 字符串替換// 將字節(jié)數(shù)組中的 子字符串 before 替換為 after// 其他重載的同名函數(shù)可參考Qt幫助文檔, 此處略QByteArray &QByteArray::replace(const QByteArray &before, const QByteArray &after);
子字符串查找和判斷
// 判斷字節(jié)數(shù)組中是否包含子字符串 ba, 包含返回true, 否則返回falsebool QByteArray::contains(const QByteArray &ba) const;bool QByteArray::contains(const char *ba) const;// 判斷字節(jié)數(shù)組中是否包含子字符 ch, 包含返回true, 否則返回falsebool QByteArray::contains(char ch) const;// 判斷字節(jié)數(shù)組是否以字符串 ba 開始, 是返回true, 不是返回falsebool QByteArray::startsWith(const QByteArray &ba) const;bool QByteArray::startsWith(const char *ba) const;// 判斷字節(jié)數(shù)組是否以字符 ch 開始, 是返回true, 不是返回falsebool QByteArray::startsWith(char ch) const;// 判斷字節(jié)數(shù)組是否以字符串 ba 結(jié)尾, 是返回true, 不是返回falsebool QByteArray::endsWith(const QByteArray &ba) const;bool QByteArray::endsWith(const char *ba) const;// 判斷字節(jié)數(shù)組是否以字符 ch 結(jié)尾, 是返回true, 不是返回falsebool QByteArray::endsWith(char ch) const;
遍歷
// 使用迭代器iterator QByteArray::begin();iterator QByteArray::end();// 使用數(shù)組的方式進(jìn)行遍歷// i的取值范圍 0 <= i < size()char QByteArray::at(int i) const;char QByteArray::operator[](int i) const;
查看字節(jié)數(shù)
// 返回字節(jié)數(shù)組對象中字符的個數(shù)int QByteArray::length() const;int QByteArray::size() const;int QByteArray::count() const;// 返回字節(jié)數(shù)組對象中 子字符串ba 出現(xiàn)的次數(shù)int QByteArray::count(const QByteArray &ba) const;int QByteArray::count(const char *ba) const;// 返回字節(jié)數(shù)組對象中 字符串ch 出現(xiàn)的次數(shù)int QByteArray::count(char ch) const;
類型轉(zhuǎn)換
// 將QByteArray類型的字符串 轉(zhuǎn)換為 char* 類型char *QByteArray::data();const char *QByteArray::data() const;// int, short, long, float, double -> QByteArray// 其他重載的同名函數(shù)可參考Qt幫助文檔, 此處略QByteArray &QByteArray::setNum(int n, int base = 10);QByteArray &QByteArray::setNum(short n, int base = 10);QByteArray &QByteArray::setNum(qlonglong n, int base = 10);QByteArray &QByteArray::setNum(float n, char f = 'g', int prec = 6);QByteArray &QByteArray::setNum(double n, char f = 'g', int prec = 6);[static] QByteArray QByteArray::number(int n, int base = 10);[static] QByteArray QByteArray::number(qlonglong n, int base = 10);[static] QByteArray QByteArray::number(double n, char f = 'g', int prec = 6);// QByteArray -> int, short, long, float, doubleint QByteArray::toInt(bool *ok = Q_NULLPTR, int base = 10) const;short QByteArray::toShort(bool *ok = Q_NULLPTR, int base = 10) const;long QByteArray::toLong(bool *ok = Q_NULLPTR, int base = 10) const;float QByteArray::toFloat(bool *ok = Q_NULLPTR) const;double QByteArray::toDouble(bool *ok = Q_NULLPTR) const;// std::string -> QByteArray[static] QByteArray QByteArray::fromStdString(const std::string &str);// QByteArray -> std::stringstd::string QByteArray::toStdString() const;// 所有字符轉(zhuǎn)換為大寫QByteArray QByteArray::toUpper() const;// 所有字符轉(zhuǎn)換為小寫QByteArray QByteArray::toLower() const;3.2 QString
QString也是封裝了字符串, 但是內(nèi)部的編碼為utf8, UTF-8屬于Unicode字符集, 它固定使用多個字節(jié)(window為2字節(jié), linux為3字節(jié))來表示一個字符,這樣可以將世界上幾乎所有語言的常用字符收錄其中。
下面給大家介紹一下這個類中常用的一些API函數(shù)。
構(gòu)造函數(shù)// 構(gòu)造一個空字符串對象QString();// 將 char* 字符串 轉(zhuǎn)換為 QString 類型QString(const char *str);// 將 QByteArray 轉(zhuǎn)換為 QString 類型QString(const QByteArray &ba);// 其他重載的同名構(gòu)造函數(shù)可參考Qt幫助文檔, 此處略數(shù)據(jù)操作
// 尾部追加數(shù)據(jù)QString& append(const QString &str);QString& append(const char *str);QString& append(const QByteArray &ba);void push_back(const QString &other);// 頭部添加數(shù)據(jù)QString& prepend(const QString &str);QString& prepend(const char *str);QString& prepend(const QByteArray &ba);void QString::push_front(const QString &other);// 插入數(shù)據(jù), 將 str 插入到字符串第 position 個字符的位置(從0開始)QString& insert(int position, const QString &str);QString& insert(int position, const char *str);QString& insert(int position, const QByteArray &str);// 刪除數(shù)據(jù)// 從大字符串中刪除len個字符, 從第pos個字符的位置開始刪除QString& remove(int position, int n);// 從字符串的尾部刪除 n 個字符void chop(int n);// 從字節(jié)串的 position 位置將字符串截斷 (前邊部分留下, 后邊部分被刪除)void truncate(int position);// 將對象中的數(shù)據(jù)清空, 使其為nullvoid clear();// 字符串替換// 將字節(jié)數(shù)組中的 子字符串 before 替換為 after// 參數(shù) cs 為是否區(qū)分大小寫, 默認(rèn)區(qū)分大小寫QString& replace(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);子字符串查找和判斷
// 參數(shù) cs 為是否區(qū)分大小寫, 默認(rèn)區(qū)分大小寫// 其他重載的同名函數(shù)可參考Qt幫助文檔, 此處略// 判斷字符串中是否包含子字符串 str, 包含返回true, 否則返回falsebool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;// 判斷字符串是否以字符串 ba 開始, 是返回true, 不是返回falsebool startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;// 判斷字符串是否以字符串 ba 結(jié)尾, 是返回true, 不是返回falsebool endsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;遍歷
// 使用迭代器iterator begin();iterator end();// 使用數(shù)組的方式進(jìn)行遍歷const QChar at(int position) constconst QChar operator[](int position) const;查看字節(jié)數(shù)
// 返回字節(jié)數(shù)組對象中字符的個數(shù)int length() const;int size() const;int count() const;// 返回字節(jié)串對象中 子字符串 str 出現(xiàn)的次數(shù)// 參數(shù) cs 為是否區(qū)分大小寫, 默認(rèn)區(qū)分大小寫int count(const QStringRef &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;類型轉(zhuǎn)換
// int, short, long, float, double -> QString// 其他重載的同名函數(shù)可參考Qt幫助文檔, 此處略QString& setNum(int n, int base = 10);QString& setNum(short n, int base = 10);QString& setNum(long n, int base = 10);QString& setNum(float n, char format = 'g', int precision = 6);QString&QString::setNum(double n, char format = 'g', int precision = 6);[static] QString QString::number(long n, int base = 10);[static] QString QString::number(int n, int base = 10);[static] QString QString::number(double n, char format = 'g', int precision = 6);// QString -> int, short, long, float, doubleint QString::toInt(bool *ok = Q_NULLPTR, int base = 10) const;short QString::toShort(bool *ok = Q_NULLPTR, int base = 10) const;long QString::toLong(bool *ok = Q_NULLPTR, int base = 10) constfloat QString::toFloat(bool *ok = Q_NULLPTR) const;double QString::toDouble(bool *ok = Q_NULLPTR) const;// 所有字符轉(zhuǎn)換為大寫QString QString::toUpper() const;// 所有字符轉(zhuǎn)換為小寫QString QString::toLower() const;字符串格式化
C語言中有sprintf()函數(shù),QString也提供了一個asprintf()函數(shù)。
QString res = QString::asprintf("fileName:%s size:%d","./av.jpg",20); qDebug()<<res<<endl;
不過QString還提供的另一種格式化字符串輸出的函數(shù)arg(),更為方便。
QString arg(const QString &a, int fieldwidth="360px",height="auto" />
【領(lǐng)更多QT學(xué)習(xí)資料,點(diǎn)擊下方鏈接免費(fèi)領(lǐng)取↓↓,先碼住不迷路~】
點(diǎn)擊→領(lǐng)Qt開發(fā)必備技術(shù)棧學(xué)習(xí)路線+資料
3.2 不同字符串類型相互轉(zhuǎn)換// std::string -> QString[static] QString QString::fromStdString(const std::string &str);// QString -> std::stringstd::string QString::toStdString() const;#QString -> QByteArray// 轉(zhuǎn)換為本地編碼, 跟隨操作系統(tǒng)QByteArray QString::toLocal8Bit() const;// 轉(zhuǎn)換為 Latin-1 編碼的字符串 不支持中文QByteArray QString::toLatin1() const;// 轉(zhuǎn)換為 utf8 編碼格式的字符串 (常用)QByteArray QString::toUtf8() const;#QByteArray -> QString//使用QString的構(gòu)造函數(shù)即可4. QVariant
QVariant(變體數(shù)據(jù)類型)這個類很神奇,或者說方便。很多時候,需要幾種不同的數(shù)據(jù)類型需要傳遞,如果用結(jié)構(gòu)體,又不大方便,容器保存的也只是一種數(shù)據(jù)類型,而QVariant則可以統(tǒng)統(tǒng)搞定。
QVariant 這個類型充當(dāng)著最常見的數(shù)據(jù)類型的聯(lián)合。QVariant 可以保存很多Qt的數(shù)據(jù)類型,包括QBrush、QColor、QCursor、QDateTime、QFont、QKeySequence、 QPalette、QPen、QPixmap、QPoint、QRect、QRegion、QSize和QString,并且還有C++基本類型,如int、float等。
4.1 標(biāo)準(zhǔn)類型將標(biāo)準(zhǔn)類型轉(zhuǎn)換為QVariant類型// 這類轉(zhuǎn)換需要使用QVariant類的構(gòu)造函數(shù), 由于比較多, 大家可自行查閱Qt幫助文檔, 在這里簡單寫幾個QVariant(int val);QVariant(bool val);QVariant(double val);QVariant(const char *val);QVariant(const QByteArray &val);QVariant(const QString &val);...... // 使用設(shè)置函數(shù)也可以將支持的類型的數(shù)據(jù)設(shè)置到QVariant對象中// 這里的 T 類型, 就是QVariant支持的類型void setValue(const T &value);// 該函數(shù)行為和 setValue() 函數(shù)完全相同[static] QVariant fromValue(const T &value);
Exmple
QVariant v(5);QVariant v;v.setValue(5);QVariant v = QVariant::fromValue(5);int i = v.toInt(); // i is now 5QString s = v.toString(); // s is now "5"判斷 QVariant中封裝的實(shí)際數(shù)據(jù)類型
Type 是枚舉類型
//獲取類型,返回的是一個枚舉類型;如QVariant::Int ...Type type() const;//獲取類型名const char *typeName() const;//根據(jù)類型id(枚舉)獲取類型名(字符串)[static] const char *typeToName(int typeId);//根據(jù)類型名(字符串)獲取類型id(枚舉)[static] Type nameToType(const char *name);將QVariant對象轉(zhuǎn)換為實(shí)際的數(shù)據(jù)類型
//在轉(zhuǎn)換之前可以先判斷能夠轉(zhuǎn)換成對應(yīng)的類型bool canConvert(int targetTypeId) constbool canConvert() constbool toBool() const;QByteArray toByteArray() const;double toDouble(bool *ok = Q_NULLPTR) const;float toFloat(bool *ok = Q_NULLPTR) const;int toInt(bool *ok = Q_NULLPTR) const;QString toString() const;......T value() const//v.value<int>();4.2 自定義類型
除了標(biāo)準(zhǔn)類型, 我們自定義的類型也可以使用QVariant類進(jìn)行封裝, 被QVariant存儲的數(shù)據(jù)類型需要有一個默認(rèn)的構(gòu)造函數(shù)和一個拷貝構(gòu)造函數(shù)。為了實(shí)現(xiàn)這個功能,首先必須使用Q_DECLARE_METATYPE()宏。通常會將這個宏放在類的聲明所在頭文件的下面, 原型為:
Q_DECLARE_METATYPE(Type)
使用的具體步驟如下:
第一步: 定義類型,并注冊//自定義類型class Animal{public: Animal(){} //必須要有默認(rèn)構(gòu)造函數(shù) //拷貝構(gòu)造函數(shù)也必須有,不過沒有深、淺拷貝時,用默認(rèn)的即可 Animal(QString name):_name(name){} void show() { qDebug()<<"Animal show name is :"<< _name <<endl; }private: QString _name;};//自定義類型注冊Q_DECLARE_METATYPE(Animal);第二步: 使用forvalue()存儲對象
int main(){ //QVariant vt(Animal("snake")); //不可以通過構(gòu)造函數(shù)存自定義類型 QVariant vt; //有以下兩種方法可以,存自定義類型 vt = QVariant::fromValue(Animal("dog")); //① vt.setValue(Animal("cat")); //② //如果能轉(zhuǎn)換到Animal類型,就轉(zhuǎn)換 if(vt.canConvert<Animal>()) { Animal animal = vt.value<Animal>(); animal.show(); } return 0;}
操作涉及的API如下:
// 如果當(dāng)前QVariant對象可用轉(zhuǎn)換為對應(yīng)的模板類型 T, 返回true, 否則返回falsebool canConvert() const;// 將當(dāng)前QVariant對象轉(zhuǎn)換為實(shí)際的 T 類型T value() const;5. 位置和尺寸
在QT中我們常見的 點(diǎn), 線, 尺寸, 矩形 都被進(jìn)行了封裝, 下邊依次為大家介紹相關(guān)的類。
5.1 QPointQPoint類封裝了我們常用用到的坐標(biāo)點(diǎn) (x, y), 常用的 API如下:
void QPoint::setX(int x);void QPoint::setY(int y);int QPoint::x() const;int &QPoint::rx();int QPoint::y() const;int &QPoint::ry();//如果x和y坐標(biāo)都為0則返回true,否則返回falsebool isNull() const//返回x()和y()的絕對值之和,傳統(tǒng)上稱為從原點(diǎn)到該點(diǎn)的向量的“曼哈頓長度”。//(p1-p2).manhattanLength(); int manhattanLength() const //返回一個交換了x和y坐標(biāo)的點(diǎn): QPoint{1, 2}.transposed() // {2, 1} QPoint transposed() const // 直接通過坐標(biāo)對象進(jìn)行算術(shù)運(yùn)算: 加減乘除QPoint &QPoint::operator*=(float factor);QPoint &QPoint::operator*=(double factor);QPoint &QPoint::operator*=(int factor);QPoint &QPoint::operator+=(const QPoint &point);QPoint &QPoint::operator-=(const QPoint &point);QPoint &QPoint::operator/=(qreal divisor);...5.2 QLine
QLine是一個直線類, 封裝了兩個坐標(biāo)點(diǎn) (兩點(diǎn)確定一條直線)
常用API如下:
// 設(shè)置直線的起點(diǎn)坐標(biāo)void setP1(const QPoint &p1);// 設(shè)置直線的終點(diǎn)坐標(biāo)void setP2(const QPoint &p2);void setPoints(const QPoint &p1, const QPoint &p2);void setLine(int x1, int y1, int x2, int y2);QPoint p1() const; // 返回直線的起始點(diǎn)坐標(biāo)QPoint p2() const; // 返回直線的終點(diǎn)坐標(biāo)QPoint center() const; // 返回值直線的中心點(diǎn)坐標(biāo), (p1() + p2()) / 2 int x1() const; // 返回值直線起點(diǎn)的 x 坐標(biāo)int y1() const; // 返回值直線起點(diǎn)的 y 坐標(biāo)int x2() const; // 返回值直線終點(diǎn)的 x 坐標(biāo)int y2() const; // 返回值直線終點(diǎn)的 y 坐標(biāo)int dx() const //返回直線向量的水平分量 int dy() const //返回直線向量的垂直分量 // 用給定的坐標(biāo)點(diǎn)平移這條直線void translate(const QPoint &offset);void translate(int dx, int dy);// 用給定的坐標(biāo)點(diǎn)平移這條直線, 返回平移之后的坐標(biāo)點(diǎn)(不會改變這條線的坐標(biāo))QLine translated(const QPoint &offset) const;QLine translated(int dx, int dy) const;// 直線對象進(jìn)行比較bool operator!=(const QLine &line) const;bool operator==(const QLine &line) const;5.3 QSize
在QT中QSize類用來形容長度和寬度, 常用的API如下:
void setwidth="360px",height="auto" />
5.4 QRect在Qt中使用 QRect類來描述一個矩形, 常用的API如下:
// 構(gòu)造一個空對象QRect::QRect();// 基于左上角坐標(biāo), 和右下角坐標(biāo)構(gòu)造一個矩形對象QRect::QRect(const QPoint &topLeft, const QPoint &bottomRight);// 基于左上角坐標(biāo), 和 寬度, 高度構(gòu)造一個矩形對象QRect::QRect(const QPoint &topLeft, const QSize &size);// 通過 左上角坐標(biāo)(x, y), 和 矩形尺寸(width="360px",height="auto" />
QPoint,QLine,QSize,QRect各自都還有浮點(diǎn)型版本的,分別是QPointF,QLineF,QSizeF,QRectF,函數(shù)基本一樣
6. 日期和時間6.1. QDate// 構(gòu)造函數(shù)QDate::QDate();QDate::QDate(int y, int m, int d);// 公共成員函數(shù)// 重新設(shè)置日期對象中的日期bool QDate::setDate(int year, int month, int day);// 給日期對象添加 ndays 天QDate QDate::addDays(qint64 ndays) const;// 給日期對象添加 nmonths 月QDate QDate::addMonths(int nmonths) const;// 給日期對象添加 nyears 月QDate QDate::addYears(int nyears) const;// 得到日期對象中的年/月/日int QDate::year() const;int QDate::month() const;int QDate::day() const;void QDate::getDate(int *year, int *month, int *day) const; /*日期對象格式化 d - 沒有前導(dǎo)零的日子 (1 to 31) dd - 前導(dǎo)為0的日子 (01 to 31) ddd - 顯示(縮寫) 周一、周二、周三、周四、周五、周六、周日 dddd - 顯示(完整) 星期一、星期二、星期三、星期四、星期五、星期六、星期日 M - 沒有前導(dǎo)零的月份(1到12) MM - 前導(dǎo)零的月份(01到12) MMM - 縮寫 1月、2月、3月... MMMM - 完整 一月、二月、三月... yy - 兩個數(shù)字的年 (00 to 99) yyyy - 以四位數(shù)表示的年份*/QString QDate::toString(const QString &format) const;// 操作符重載 ==> 日期比較bool QDate::operator!=(const QDate &d) const;bool QDate::operator<(const QDate &d) const;bool QDate::operator<=(const QDate &d) const;bool QDate::operator==(const QDate &d) const;bool QDate::operator>(const QDate &d) const;bool QDate::operator>=(const QDate &d) const;// 靜態(tài)函數(shù) -> 得到本地的當(dāng)前日期[static] QDate QDate::currentDate();6.2. QTime
【領(lǐng)更多QT學(xué)習(xí)資料,點(diǎn)擊下方鏈接免費(fèi)領(lǐng)取↓↓,先碼住不迷路~】
點(diǎn)擊→領(lǐng)Qt開發(fā)必備技術(shù)棧學(xué)習(xí)路線+資料
// 構(gòu)造函數(shù)QTime::QTime();/* h ==> must be in the range 0 to 23 m and s ==> must be in the range 0 to 59 ms ==> must be in the range 0 to 999*/ QTime::QTime(int h, int m, int s = 0, int ms = 0);// 公共成員函數(shù)// Returns true if the set time is valid; otherwise returns false.bool QTime::setHMS(int h, int m, int s, int ms = 0);QTime QTime::addSecs(int s) const;QTime QTime::addMSecs(int ms) const;// 示例代碼 QTime n(14, 0, 0); // n == 14:00:00 QTime t; t = n.addSecs(70); // t == 14:01:10 t = n.addSecs(-70); // t == 13:58:50 t = n.addSecs(10 * 60 * 60 + 5); // t == 00:00:05 t = n.addSecs(-15 * 60 * 60); // t == 23:00:00// 從時間對象中取出 時/分/秒/毫秒// Returns the hour part (0 to 23) of the time. Returns -1 if the time is invalid.int QTime::hour() const;// Returns the minute part (0 to 59) of the time. Returns -1 if the time is invalid.int QTime::minute() const;// Returns the second part (0 to 59) of the time. Returns -1 if the time is invalid.int QTime::second() const;// Returns the millisecond part (0 to 999) of the time. Returns -1 if the time is invalid.int QTime::msec() const;// 時間格式化/* -- 時 h ==> The hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display) hh ==> The hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display) H ==> The hour without a leading zero (0 to 23, even with AM/PM display) HH ==> The hour with a leading zero (00 to 23, even with AM/PM display) -- 分 m ==> The minute without a leading zero (0 to 59) mm ==> The minute with a leading zero (00 to 59) -- 秒 s ==> The whole second, without any leading zero (0 to 59) ss ==> The whole second, with a leading zero where applicable (00 to 59) -- 毫秒 zzz ==> The fractional part of the second, to millisecond precision, including trailing zeroes where applicable (000 to 999). -- 上午或者下午 AP or A ==> 使用AM/PM(大寫) 描述上下午, 中文系統(tǒng)顯示漢字 ap or a ==> 使用am/pm(小寫) 描述上下午, 中文系統(tǒng)顯示漢字*/QString QTime::toString(const QString &format) const;// 操作符重載 ==> 時間比較bool QTime::operator!=(const QTime &t) const;bool QTime::operator<(const QTime &t) const;bool QTime::operator<=(const QTime &t) const;bool QTime::operator==(const QTime &t) const;bool QTime::operator>(const QTime &t) const;bool QTime::operator>=(const QTime &t) const;// 靜態(tài)函數(shù) -> 得到當(dāng)前時間[static] QTime QTime::currentTime();經(jīng)時計(jì)時器
QTime的經(jīng)時計(jì)時器已經(jīng)過時了,推薦使用QElapsedTimer。
//QTime已廢棄的函數(shù)// 開始計(jì)時void QTime::start();// 計(jì)時結(jié)束int QTime::elapsed() const;// 重新計(jì)時int QTime::restart();// 推薦使用的API函數(shù)// QElapsedTimer 類void QElapsedTimer::start();qint64 QElapsedTimer::restart();qint64 QElapsedTimer::elapsed() const;主要的使用方法就是測量一個操作耗時多久,例子如下:QElapsedTimer elapse; elapse.start(); for(int i = 0;i<10000000;i++); qDebug()<<elapse.elapsed()<<endl;6.3. QDateTime
// 構(gòu)造函數(shù)QDateTime::QDateTime();QDateTime::QDateTime(const QDate &date, const QTime &time, Qt::TimeSpec spec = Qt::LocalTime);// 公共成員函數(shù)// 設(shè)置日期void QDateTime::setDate(const QDate &date);// 設(shè)置時間void QDateTime::setTime(const QTime &time);// 給當(dāng)前日期對象追加 年/月/日/秒/毫秒, 參數(shù)可以是負(fù)數(shù)QDateTime QDateTime::addYears(int nyears) const;QDateTime QDateTime::addMonths(int nmonths) const;QDateTime QDateTime::addDays(qint64 ndays) const;QDateTime QDateTime::addSecs(qint64 s) const;QDateTime QDateTime::addMSecs(qint64 msecs) const;// 得到對象中的日期QDate QDateTime::date() const;// 得到對象中的時間QTime QDateTime::time() const;// 日期和時間格式, 格式字符參考QDate 和 QTime 類的 toString() 函數(shù)QString QDateTime::toString(const QString &format) const;// 操作符重載 ==> 日期時間對象的比較bool QDateTime::operator!=(const QDateTime &other) const;bool QDateTime::operator<(const QDateTime &other) const;bool QDateTime::operator<=(const QDateTime &other) const;bool QDateTime::operator==(const QDateTime &other) const;bool QDateTime::operator>(const QDateTime &other) const;bool QDateTime::operator>=(const QDateTime &other) const;// 靜態(tài)函數(shù)// 得到當(dāng)前時區(qū)的日期和時間(本地設(shè)置的時區(qū)對應(yīng)的日期和時間)[static] QDateTime QDateTime::currentDateTime();7. 容器
Qt中提供了一組通用的基于模板的容器類(container class)??梢杂脕泶鎯χ付ǖ捻?xiàng)(items),與STL(C++標(biāo)準(zhǔn)模板庫)相比,Qt中的容器更輕量,更安全,功能更強(qiáng)大。
序列式容器QListQLinkedListQVectorQStackQQueue對于大多數(shù)應(yīng)用程序,QList是最好的類型。雖然它是作為數(shù)組列表實(shí)現(xiàn)的,但是它提供了非??斓那爸煤透郊印H绻阏娴男枰粋€鏈表,使用QLinkedList;如果您希望您的項(xiàng)目占用連續(xù)的內(nèi)存位置,請使用QVector。QStack和QQueue是提供LIFO和FIFO語義的便利類。關(guān)聯(lián)式容器QMapQMultiMapQHashQMultiHashQSet“multi”容器方便地支持與單個鍵相關(guān)聯(lián)的多個值?!癶ash”容器通過使用哈希函數(shù)而不是對排序集進(jìn)行二進(jìn)制搜索,從而提供更快的查找。作為特殊情況,QCache和QContiguousCache類在有限的緩存存儲中提供了對象的高效散列查找。遍歷容器: iteratorQt提供了兩種遍歷容器的風(fēng)格:
java風(fēng)格的迭代器和stl風(fēng)格的迭代器。java風(fēng)格的迭代器更容易使用并提供高級功能,而STL風(fēng)格的迭代器稍微更高效,可以與Qt和STL的通用算法一起使用。
java風(fēng)格容器
只讀迭代器
讀寫迭代器
QList<T>,QQueue<T>
QListIterator<T>
QMutableListIterator<T>
QLinkedList<T>
QLinkedListIterator<T>
QMutableLinkedListIterator<T>
QVector<T>,QStack<T>
QVectorIterator<T>
QMutableVectorIterator<T>
QSet<T>
QSetIterator<T>
QMutableSetIterator<T>
QMap<Key,T>,QMultiMap<Key,T>
QMapIterator<T>
QMutableMapIterator<T>
QHash<Key,T>,QMultiHash<Key,T>
QHashIterator<T>
QMutableHashIterator<T>
STL風(fēng)格容器
只讀迭代器
讀寫迭代器
QList<T>,QQueue<T>
QList<T>::const_iterator
QList<T>::iterator
QLinkedList<T>
QLinkedList<T>::const_iterator
QLinkedList<T>::iterator
QVector<T>,QStack<T>
QVector<T>::const_iterator
QVector<T>::iterator
QSet<T>
QSet<T>::const_iterator
QSet<T>::iterator
QMap<Key,T>,QMultiMap<Key,T>
QMap<T>::const_iterator
QMap<T>::iterator
QHash<Key,T>,QMultiHash<Key,T>
QHash<T>::const_iterator
QHash<T>::iterator
//java風(fēng)格迭代器QList<int> list;list<<1<<2<<3<<4<<5;QListIterator<int> it(list);while (it.hasNext()){ qDebug()<<it.next();}//STL風(fēng)格迭代器QList<int> list2 = {1,2,3,4,5};QList<int>::iterator it;//定義一個讀寫迭代器for(it=list2.begin(); it!=list2.end(); it++){ qDebug()<<*it;}序列式容器QList
QList模板提供了一個列表,實(shí)際上是一個指針數(shù)組,當(dāng)項(xiàng)目數(shù)小于1000時,可以實(shí)現(xiàn)快速的插入刪除操作
QList<T> 是 Qt 的通用容器類之一。它將項(xiàng)目存儲在一個列表中,該列表提供基于索引的快速訪問和基于索引的插入和刪除。 QList<T>、QLinkedList<T> 和 QVector<T> 提供類似的 API 和功能。它們通??梢曰Q,但會產(chǎn)生性能后果。
使用概述:
QVector 應(yīng)該是您的默認(rèn)首選。 QVector<T> 通常會比 QList<T> 提供更好的性能,因?yàn)?QVector<T> 總是將其項(xiàng)按順序存儲在內(nèi)存中,其中 QList<T> 將在堆上分配它的項(xiàng),除非 sizeof(T) <= sizeof(void *) 并且 T 已使用 Q_DECLARE_TYPEINFO 聲明為 Q_MOVABLE_TYPE 或 Q_PRIMITIVE_TYPE。然而,QList 在整個 Qt API 被大量使用,用于傳遞參數(shù)和返回值。 使用 QList可以很方便的與這些 API 進(jìn)行交互。如果您需要一個真正的鏈表,它保證常量時間內(nèi)插入列表,并且使用迭代器指向項(xiàng)而不是索引,那么請使用QLinkedList。公有函數(shù)添加數(shù)據(jù)//支持流插入QList<int>()<<1<<2<<3<<4<<5;void append(const T &value)void append(const QList<T> &value) void insert(int i, const T &value)QList::iterator insert(QList::iterator before, const T &value)void prepend(const T &value)void push_back(const T &value)void push_front(const T &value)獲取數(shù)據(jù)
T &back()const T &back() const T &first()const T &first() constT &front()const T &front() const T &last()const T &last() const const T &constFirst() constconst T &constLast() const//返回下標(biāo)為i的元素,如果下標(biāo)i不合法,則返回defaultValueT value(int i) constT value(int i, const T &defaultValue) const const T &at(int i) constT &operator[](int i)const T &operator[](int i) const//返回從位置pos開始的子列表。如果length為-1(默認(rèn)),則包含pos中的所有元素; QList<T> mid(int pos, int length = -1) const刪除數(shù)據(jù)
void clear() QList::iterator erase(QList::iterator pos)QList::iterator erase(QList::iterator begin, QList::iterator end) void pop_back()void pop_front()//刪除元素 int removeAll(const T &value)bool removeOne(const T &value)void removeAt(int i)void removeFirst()void removeLast()//刪除元素并返回它,如果不使用返回值,removeAt()會更高效 T takeAt(int i)T takeFirst()T takeLast()查找/替換
//返回value在列表中第一次出現(xiàn)的索引位置,從索引位置from向前搜索。 如果沒有匹配的項(xiàng),則返回-1。 int indexOf(const T &value, int from = 0) const//返回value在列表中最后一次出現(xiàn)的索引位置,從索引位置from反向搜索。如果from是-1(默認(rèn)值),則搜索從最后一項(xiàng)開始。如果沒有匹配的項(xiàng),則返回-1。 int lastIndexOf(const T &value, int from = -1) const//將索引位置為i的項(xiàng)替換為valuevoid replace(int i, const T &value)//如果列表中包含值的出現(xiàn),則返回true; 否則返回false。 該函數(shù)要求值類型具有operator==()的實(shí)現(xiàn)。 bool contains(const T &value) const交換/移動
//將索引位置from到索引位置to //["A", "B", "C", "D", "E", "F"] move(1,4)-> ["A", "C", "D", "E", "B", "F"]void move(int from, int to)void swap(QList<T> &other)//交換下標(biāo)i j的元素 void swapItemsAt(int i, int j)判斷函數(shù)
int count(const T &value) constint count() constint size() constint length() constbool empty() constbool isEmpty() const//如果列表第一項(xiàng)/后一項(xiàng)等于value,則返回true; 否則返回false。 bool startsWith(const T &value) const bool endsWith(const T &value) const//預(yù)分配空間大小 void reserve(int alloc)和其他容器互轉(zhuǎn)
QSet<T> toSet() conststd::list<T> toStdList() constQVector<T> toVector() const[static] QList<T> fromSet(const QSet<T> &set)[static] QList<T> fromStdList(const std::list<T> &list)[static] QList<T> fromVector(const QVector<T> &vector)QStringList
QStringList繼承自QList<QString>。 它提供基于索引的快速訪問以及快速插入和刪除。 將字符串列表作為值參數(shù)傳遞既快速又安全。 QList的所有功能也適用于QStringList。 例如,可以使用isEmpty()來測試列表是否為空,還可以調(diào)用append()、prepend()、insert()、replace()、removeAll()、removeAt()、removeFirst()、removeLast()和removeOne()等函數(shù)來修改QStringList。 此外,QStringList提供了一些方便的函數(shù),使處理字符串列表更容易:
判斷是否包含某個字符串bool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) constbool contains(QLatin1String str, Qt::CaseSensitivity cs = Qt::CaseSensitive) constbool contains(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const過濾:返回包含子字符串str的所有字符串的列表
QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) constQStringList filter(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) constQStringList filter(const QRegExp &rx) constQStringList filter(const QRegularExpression &re) const查找
//從左往右查找int indexOf(const QRegExp &rx, int from = 0) constint indexOf(QStringView str, int from = 0) constint indexOf(QLatin1String str, int from = 0) constint indexOf(QRegExp &rx, int from = 0) constint indexOf(const QRegularExpression &re, int from = 0) const //從右往左查找 int lastIndexOf(const QRegExp &rx, int from = -1) constint lastIndexOf(QStringView str, int from = -1) constint lastIndexOf(QLatin1String str, int from = -1) constint lastIndexOf(QRegExp &rx, int from = -1) constint lastIndexOf(const QRegularExpression &re, int from = -1) const連接:將QStringList中的所有字符串連接為一個字符串,每個元素由給定的分隔符(可以是空串)分隔。
//支持流插入 <<QString join(const QString &separator) constQString join(QStringView separator) constQString join(QLatin1String separator) constQString join(QChar separator) const刪除:從QStringList中刪除重復(fù)的元素。 返回已刪除元素的數(shù)量。
int removeDuplicates()替換:返回一個字符串列表,其中每個字符串在找到before文本時都將before文本替換為after文本【領(lǐng)更多QT學(xué)習(xí)資料,點(diǎn)擊下方鏈接免費(fèi)領(lǐng)取↓↓,先碼住不迷路~】
點(diǎn)擊→領(lǐng)Qt開發(fā)必備技術(shù)棧學(xué)習(xí)路線+資料
QStringList &replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive)QStringList &replaceInStrings(QStringView before, QStringView after, Qt::CaseSensitivity cs = Qt::CaseSensitive)QStringList &replaceInStrings(const QString &before, QStringView after, Qt::CaseSensitivity cs = Qt::CaseSensitive)QStringList &replaceInStrings(QStringView before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive)QStringList &replaceInStrings(const QRegExp &rx, const QString &after)QStringList &replaceInStrings(const QRegularExpression &re, const QString &after)排序:升序
void sort(Qt::CaseSensitivity cs = Qt::CaseSensitive)QLinkedList
單鏈表
QVector//返回vector底層數(shù)組指針。只要不重新分配vector對象,指針就保持有效。 這個函數(shù)在將vector傳遞給接受普通c++數(shù)組的函數(shù)時非常有用。 T *data()const T *data() const//將value賦給向量中的所有項(xiàng)。 如果size不同于-1(默認(rèn)值),則vector的大小將被調(diào)整為size之前的大小。QVector<T> &fill(const T &value, int size = -1)QStack
T pop()void push(const T &t)void swap(QStack<T> &other)T &top()const T &top() constQQueue
//刪除隊(duì)頭并返回它 T dequeue()//將值t加到隊(duì)尾 void enqueue(const T &t)//返回隊(duì)頭的引用T &head()const T &head() const void swap(QQueue<T> &other)關(guān)聯(lián)式容器QMap
QMap<Key, T> 是 Qt 的通用容器類之一。 它存儲(鍵,值)對,并提供與鍵關(guān)聯(lián)的值的快速查找。 QMap 和 QHash 提供非常相似的功能。 區(qū)別在于:
QHash 提供比 QMap 更快的平均查找速度。在迭代 QHash 時,項(xiàng)目是任意排序的。 使用 QMap,項(xiàng)目總是按鍵排序。QHash 的鍵類型必須提供 operator==() 和全局 qHash(Key) 函數(shù)。 QMap 的鍵類型必須提供 operator<() 指定總順序。 從 Qt 5.8.1 開始,使用指針類型作為鍵也是安全的,即使底層 operator<() 不提供全序。公有函數(shù)添加數(shù)據(jù)//插入新的鍵值對,如果已經(jīng)有一個鍵為key的項(xiàng),則該項(xiàng)的值將被value替換;如果有多個鍵為key的項(xiàng),則最近插入的項(xiàng)的值將被value替換。 QMap::iterator insert(const Key &key, const T &value)QMap::iterator insert(QMap::const_iterator pos, const Key &key, const T &value)//插入新的鍵值對,如果在map中已經(jīng)有一個具有相同鍵的項(xiàng),這個函數(shù)將創(chuàng)建一個新的項(xiàng) QMap::iterator insertMulti(const Key &key, const T &value)QMap::iterator insertMulti(QMap::const_iterator pos, const Key &key, const T &value)獲取數(shù)據(jù)
T &first()const T &first() constconst Key &firstKey() const const Key key(const T &value, const Key &defaultKey = Key()) const QList<Key> keys() constQList<Key> keys(const T &value) constT &last()const T &last() constconst Key &lastKey() const//返回一個列表,該列表包含映射中的所有鍵。 在映射中出現(xiàn)多次的鍵在返回的列表中只出現(xiàn)一次。 QList<Key> uniqueKeys() const//將其他map中的所有項(xiàng)目插入到該map中。 QMap<Key, T> &unite(const QMap<Key, T> &other)const T value(const Key &key, const T &defaultValue = T()) constQList<T> values() constQList<T> values(const Key &key) constT &operator[](const Key &key)const T operator[](const Key &key) const刪除數(shù)據(jù)
void clear()QMap::iterator erase(QMap::iterator pos)int remove(const Key &key) T take(const Key &key)查找
bool contains(const Key &key) const/* 返回兩個迭代器迭代器1:是指向當(dāng)前 map 容器中第一個大于或等于 key 的鍵值對的迭代器(lowerBound())。迭代器2:是指向當(dāng)前 map 容器中第一個大于 key 的鍵值對的迭代器。(upperBound())*/QPair<QMap::iterator, QMap::iterator> equal_range(const Key &key)QPair<QMap::const_iterator, QMap::const_iterator> equal_range(const Key &key) const QMap::iterator find(const Key &key)QMap::const_iterator find(const Key &key) const QMap::iterator lowerBound(const Key &key)QMap::const_iterator lowerBound(const Key &key) constQMap::iterator upperBound(const Key &key)QMap::const_iterator upperBound(const Key &key) const判斷
int count(const Key &key) constint count() constint size() const bool empty() constbool isEmpty() constQMultiMap插入和替換:插入新的鍵值對。如果已經(jīng)有一個鍵為key的項(xiàng),則該項(xiàng)的值將被value替換。如果有多個鍵為key的項(xiàng),則最近插入的項(xiàng)的值將被value替換。
typename QMap<Key, T>::iterator replace(const Key &key, const T &value)QHash添加數(shù)據(jù)
QHash::iterator insert(const Key &key, const T &value)QHash::iterator insertMulti(const Key &key, const T &value)獲取數(shù)據(jù)
const Key key(const T &value) constconst Key key(const T &value, const Key &defaultKey) constQList<Key> keys() constQList<Key> keys(const T &value) const QList<Key> uniqueKeys() constQHash<K, V> &unite(const QHash<K, V> &other)const T value(const Key &key) constconst T value(const Key &key, const T &defaultValue) constQList<T> values() constQList<T> values(const Key &key) const刪除數(shù)據(jù)
void clear()QHash::iterator erase(QHash::const_iterator pos)QHash::iterator erase(QHash::iterator pos) QPair<QHash::iterator, QHash::iterator> equal_range(const Key &key)QPair<QHash::const_iterator, QHash::const_iterator> equal_range(const Key &key) const int remove(const Key &key)T take(const Key &key)查找
bool contains(const Key &key) const QHash::iterator find(const Key &key)QHash::const_iterator find(const Key &key) const判斷
int count(const Key &key) constint count() constint size() const bool empty() constQMultiHash
繼承自QHash
typename QHash<Key, T>::iterator replace(const Key &key, const T &value)案例
class Grade //班級{public: Grade(int number, const QString& GradeName) :number(number),name(GradeName) {} friend QDebug operator<<(QDebug out, const Grade& stu); friend bool operator==(const Grade& left, const Grade& right); friend uint qHash(const Grade& stu, uint seed = 0);private: int number; //班級號 QString name; };QDebug operator<<(QDebug out, const Grade& stu){ out << "[" << stu.number <<"," << stu.name << "]"; return out;}bool operator==(const Grade& left, const Grade& right){ return (left.number == right.number);}uint qHash(const Grade& stu, uint seed){ return stu.number;}int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); QHash<Grade, QString> hash; hash.insert(Grade(1403, "安卓"), "張三"); hash.insert(Grade(1406, "蘋果"), "李四"); qDebug() << hash; return a.exec();}QSet添加數(shù)據(jù)
QSet::iterator insert(const T &value)獲取數(shù)據(jù)
QList<T> values() constQList<T> toList() const刪除數(shù)據(jù)
void clear()QSet::iterator erase(QSet::const_iterator pos)QSet::iterator erase(QSet::iterator pos) bool remove(const T &value)查找
bool contains(const T &value) constbool contains(const QSet<T> &other) const QSet::const_iterator find(const T &value) constQSet::iterator find(const T &value)其他
int count() constbool empty() constbool isEmpty() constint size() const交集,差集,并集
//并集:ohter集合中不在這個集合中的每一項(xiàng)都被插入到這個集合中。 返回對該集合的引用。 QSet<T> &unite(const QSet<T> &other)//差集:從該集合中刪除包含在ohter集合中的所有項(xiàng)。 返回對該集合的引用。 QSet<T> &QSet::subtract(const QSet<T> &other)//交集:從該集合中刪除ohter集合中不包含的所有項(xiàng)。 返回對該集合的引用。 QSet<T> &intersect(const QSet<T> &other)//如果該集合與ohter集合至少有一個共同項(xiàng),則返回true。 bool intersects(const QSet<T> &other) const8. 算法
直接使用STL中的算法
QtGlobalQt類的頭文件都會包含該頭文件,所以不用再顯式定義了
T qAbs(const T &t)//求絕對值//返回value限定在min至max范圍之內(nèi)的值const T &qBound(const T &min, const T &val, const T &max)//如果p1和p2近似相等,返回truebool qFuzzyCompare(double p1, double p2)bool qFuzzyCompare(float p1, float p2)//如果浮點(diǎn)數(shù)約等于0,返回true bool qFuzzyIsNull(double d)bool qFuzzyIsNull(float f)//返回?zé)o窮大的數(shù) double qInf()//求最大值和最小值const T &qMax(const T &a, const T &b)const T &qMin(const T &a, const T &b)//四舍五入到最近的整數(shù)qint64 qRound64(double d)qint64 qRound64(float d)int qRound(double d)int qRound(float d)//獲得Qt版本 const char *qVersion()QtMath常用函數(shù)
qreal qAcos(qreal v)qreal qAsin(qreal v)qreal qAtan2(qreal y, qreal x)qreal qAtan(qreal v)int qCeil(qreal v)qreal qCos(qreal v)//角度轉(zhuǎn)弧度 float qDegreesToRadians(float degrees)double qDegreesToRadians(double degrees)qreal qExp(qreal v)qreal qFabs(qreal v)int qFloor(qreal v)qreal qLn(qreal v)quint32 qNextPowerOfTwo(quint32 value)quint64 qNextPowerOfTwo(quint64 value)quint32 qNextPowerOfTwo(qint32 value)quint64 qNextPowerOfTwo(qint64 value)qreal qPow(qreal x, qreal y)float qRadiansToDegrees(float radians)double qRadiansToDegrees(double radians)qreal qSin(qreal v)qreal qSqrt(qreal v)qreal qTan(qreal v)宏
宏
含義
M_E
自然對數(shù)的底 (歐拉數(shù))
M_LOG2E
以2為底e的對數(shù)
M_LOG10E
以10為底的e的對數(shù)
M_LN2
2的自然對數(shù)
M_LN10
10的自然對數(shù)
M_PI
π
M_PI_2
π/2
M_PI_4
π/4
M_1_PI
1/π
M_2_PI
2/π
M_2_SQRTPI
2除以π的平方根,2 /√π
M_SQRT2
根號2
M_SQRT1_2
1/√π
以上就是關(guān)于pos機(jī)消費(fèi)類型c,Qt——常用數(shù)據(jù)類型的知識,后面我們會繼續(xù)為大家整理關(guān)于pos機(jī)消費(fèi)類型c的知識,希望能夠幫助到大家!
