标签:Container Qt items col1 Book values authors include
qt containers
QVector
#include <QVector>
QVector values = {1,2,3,4,5};
values.first();
values.last();
values.append(6);
values.preppend(0);
for(int val : values){
}
QList
#include <QList>
#include <algorithm>
//初始化
QList<QString> authors = {"a","b"}
//大小
authors.size();
//遍历
for(int i = 0;i<authors.size();i++){
authors.at(i);
}
//增加
autors << "c" << "d";
//排序
std::sort(authors.begin(),authors.end());
//遍历
for(QString author: authors){
}
QSet
QSet
provides a single-valued mathematical set with fast lookups. The values are stored in an unspecified order.
#include <QSet>
#include <algorithm>
//初始化
QSet<QString> col1 = {"yellow", "red", "blue"};
QSet<QString> col2 = {"blue", "pink", "orange"};
//大小
col1.size();
//插入
col1.insert("brown");
//连接
col1.unite(col2);
//遍历
for(QString val : col1){
}
//排序
std:sort(col1.begin(),col1.end());
//遍历
The
QSet
is used to store colours in the example. It makes no sense to have one colour value specified more times.
QMap
#include <QMap>
//初始化
QMap<QString, int> items = {{"coin",5},{"books",3}};
//插入
items.insert("bottles",7);
//值
items.values();
//键
items.keys();
//遍历
QMapIterator<QString, int> it(items);
whie(it.hasNext()){
it.next();
it.key();
it.value();
}
自定义类排序
#include <QList>
#include <algorithm>
#include "book"
bool compareByTitle(const Book &b1, const Book &b2){
return b1.getTitle() < b2.getTitle();
}
int main(void){
QList<Book> books = {
Book("Jack London", "The Call of the Wild"),
Book("Honoré de Balzac", "Father Goriot"),
Book("Leo Tolstoy", "War and Peace"),
Book("Gustave Flaubert", "Sentimental education"),
Book("Guy de Maupassant", "Une vie"),
Book("William Shakespeare", "Hamlet")
};
std::sort(books.begin(),books.end(),compareTyTitle)
}
标签:Container,Qt,items,col1,Book,values,authors,include
来源: https://www.cnblogs.com/mtgold/p/15528525.html
本站声明:
1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。