新建一个项目

在pro文件中只需要加上CONFIG
+= C++11

main.cpp

#include
<QMap>

int
main()

{

QMap<int,QString>
map;

map.insert(1,"1");

map.insert(2,"2");

map.insert(3,"3");

map[4]
=
"4";

if(map.find(1)
==
map.end())

{

//not
exist

}

/*

*
"1"

*
"2"

*
"3"

*
"4"

*/

foreach(int
key,map.keys())

{

QString
value
=
map[key];

qDebug()
<<
value;

}

for(auto
it
=
map.begin();
it!=map.end();
)

{

it.key();

it.value();

#if
0

if(needRemove)

{

it
= map.erase(it);

}

else

{

++i;

}

#endif

}

map.remove(1);

}

运行结果:

#include <QVector>
#include <QList>
#include <QMap>
#include <QSet>
#include <QQueue>
#include <QStack>
#include <QMultiMap>
#include <QDebug>
#include <QStringList>
 
int main()
{
    QVector<int> intVector;
    intVector << 5;
    intVector.append(15);
    intVector.push_front(10);
    intVector.push_back(20);
 
    foreach(int value, intVector)
    {
        qDebug() << value;
    }
 
    QVector<int>::iterator it;
    for(it = intVector.begin(); it!=intVector.end(); ++it)
    {
        qDebug() << *it;
    }
 
    int size = intVector.size();
    for(int i = 0; i < size; ++i)
    {
        qDebug() << intVector[i];
        qDebug() << intVector.at(i);
    }
 
    //查找
    qDebug() << intVector.indexOf(5);
 
    //sort
    qSort(intVector);
 
    //删除一个
    //intVector.removeOne(5);
    //intVector.removeAll(5);
 
    qDebug() << "sort";
    for(it = intVector.begin(); it!=intVector.end(); ++it)
    {
        qDebug() << *it;
    }
}

运行结果:



1.QT中的容器QVector,QList,QSet,QMap,QQueue,QStack,QMultiMap,QSingleList等的更多相关文章

  1. 1.QT该容器QVector,QList,QSet,QMap,QQueue,QStack,QMultiMap,QSingleList等待

    1  新建一个项目 在pro文件里仅仅须要加上CONFIG += C++11 main.cpp #include <QMap> int main() { QMap<int,QStri ...

  2. Qt中的常用容器类(解释比较全面,有插图)

    在Qt库中为我们提供了一系列的基于模板的容器类.这些类可以被用来存储特定类型的项.例如,如果你需要一个大小可以变得QString数组,那么可以使用QVector<QString>. 这些容 ...

  3. Qt中QVector与QList的应用

    首先來看看QVector 的基本使用方式,建立一個可容納兩個元素的QVector ,並使用索引方式存取元素值:QVector<double> vect(2); vect[0] = 1.0; ...

  4. PyQt(Python+Qt)学习随笔:Qt中的部分类型QString、QList和指针、引用在PyQt中的实现方式

    老猿Python博文目录 老猿Python博客地址 在我们查阅Qt的文档资料时,可以看到Qt中的链表使用的是QList,字符串使用的是QString,但老猿在测试时发现这两个类型PyQt不支持,无法找 ...

  5. Qt中的通用模板算法QtAlgorithms(qDeleteAll,qBinaryFind,qCountLeadingZeroBits,qPopulationCount,qFill,qSwap,qSort)

    Qt在<QtAlgorithms>头文件中为我们提供了一系列的全局模板方法,这些模板方法主要用于容器操作,比如qDeleteAll().其在Qt中的声明如下: void qDeleteAl ...

  6. Qt中使用ActiveX(3篇)

    由于最近需要使用ActiveX,一般来说可以使用微软提供的MFC或者ATL框架来开发,由于我个人对这部分内容不是很熟悉,好在Qt也提供对于ActiveX的支持.本文主要记录个人学习ActiveX的一些 ...

  7. Qt中常用知识点

    1:QRegExp 正则表达式 QRegExp regExp("[a-zA-Z][1-9][0-9]{0,2}"); xxx->setValidator(new QRegEx ...

  8. Qt 中的对象模型(Object Model)

    原标题:Qt 中的对象模型(Object Model)90不太后,余生皆折腾 本节内容主要讲了 Qt 对象模型比标准 C++ 对象模型多了什么内容,并介绍了组成 Qt 对象模型基础的相关的类.最后说明 ...

  9. Qt中QObject中的parent参数

    今天写了一个小程序,验证了带参的构造函数中参数parent的作用. 在MainWindow中声明一个QDialog类型的指针,在MainWindow中对它进行初始化.我采用了两种初始化方式,一种是带参 ...

随机推荐

  1. HDU2222 自动机(学习中)

    题目大意: 给你很多个单词,然后给你一篇文章,问给出的单词在文章中出现的次数. 解题思路: AC自动机入门题.需要注意的就是可能有重复单词 代码如下: #include<iostream> ...

  2. Codeforces Round #438 B. Race Against Time

    Description Have you ever tried to explain to the coordinator, why it is eight hours to the contest ...

  3. BZOJ4942【noi2017】整数

    题目背景 在人类智慧的山巅,有着一台字长为10485761048576 位(此数字与解题无关)的超级计算机,著名理论计算机科 学家P博士正用它进行各种研究.不幸的是,这天台风切断了电力系统,超级计算机 ...

  4. poj3237 树链部分 边权模板

    Tree Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 7384   Accepted: 2001 Description ...

  5. SpringCloud学习之Ribbon

    一.负载均衡与Ribbon 负载均衡,在集群中是很常见的一个“名词”,顾名思义是根据一定的算法将请求分摊至对应的服务节点上,常见的算法有如下几种: 轮询法:所有请求被依次分发到每台应用服务器上,每台服 ...

  6. CSS3中三种清除浮动(float)的方法

    方法一:添加新的元素 .应用 clear:both .clear{ clear:both; height:; height:; overflow:hidden; } 方法二:父级div定义 overf ...

  7. npm run dev 出错的解决办法

    bogon:~ yan$ cd my-project bogon:my-project yan$ npm run dev > my-project@1.0.0 dev /Users/yan/my ...

  8. SSH上一个随笔的基础上添加上hibernate支持

    配置文件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.o ...

  9. LeetCode 2

    No1 Given a sorted array and a target value, return the index if the target is found. If not, return ...

  10. 8.1 使用Python操作SQLite数据库

    SQLite是内嵌在Python中的轻量级.基于磁盘文件袋额数据库管理系统,不需要安装和配置服务,支持使用SQL语句来访问数据库.该数据库使用C语言开发,支持大多数SQL91标准,支持原子的.一致的. ...