精华内容
下载资源
问答
  • 2020-01-09 10:57:19

    1、增加

     QMap<char,int> mapCI;
     
    //插入
    mapCI.insert('a',1);
    mapCI.insertMulti('b',2);   //一键多值
    mapCI.insertMulti('b',3);
    qDebug() << mapCI;
    //将QMap插入到另一个QMap中,同键值不会被覆盖
    QMap<char,int> map1;
    map1.insert('b',2);
    map1.insert('c',4);
    mapCI.unite(map1);
    qDebug() << mapCI;
    

    2、删除

    mapCI.erase(mapCI.begin()); //删除第一个键值
    qDebug() << mapCI;
    mapCI.remove('b');  //删除 b 和他的值
    qDebug() << mapCI;
    mapCI.insert('c',4);
    qDebug() << mapCI.take('c'); //移除键c,返回它的值
    

    3、改

    mapCI.insert('a',2); //会覆盖同一个键的值,作用等同修改
    

    4、查找

    QMap<char,int>::iterator it = mapCI.find('a'); //查找,返回迭代器
    qDebug() << it.key() << it.value();
    mapCI.insert('b',2);
    qDebug() << mapCI.key(2); //返回该值得键,只返回一个键
    qDebug() << mapCI.keys(2); //返回该值得所有的键
    //返回键的链表
    QList<char> list = mapCI.uniqueKeys();
    qDebug() << list;
    //返回值得链表
    QList<int> list1 = mapCI.values();
    qDebug() << list1;
     
    //返回大小最接近b键的迭代器,从左到右
    it = mapCI.lowerBound('b');
    qDebug() << it.key() << it.value();
    //返回大小最接近b(不包括b)键的迭代器,从右到左
    it = mapCI.upperBound('b');
    qDebug() << it.key() << it.value();
    qDebug() << mapCI.contains('b');//如果含有b键,返回true
    //查找返回迭代器指针或者 end
    qDebug() << mapCI.constFind('b').value();
    

    5、转换

    std::map<char,int> map = mapCI.toStdMap();
    

    6、测试代码

    #include <QCoreApplication>
    #include <QDebug>
    #include <list>
    #include <QVector>
    #include <QMap>
     
    using namespace std;
     
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
     
        QMap<char,int> mapCI;
     
        //插入
        mapCI.insert('a',1);
        mapCI.insertMulti('b',2);   //一键多值
        mapCI.insertMulti('b',3);
        qDebug() << mapCI;
        //将QMap插入到另一个QMap中,同键值不会被覆盖
        QMap<char,int> map1;
        map1.insert('b',2);
        map1.insert('c',4);
        mapCI.unite(map1);
        qDebug() << mapCI;
     
        //删除
        mapCI.erase(mapCI.begin()); //删除第一个键值
        qDebug() << mapCI;
        mapCI.remove('b');  //删除 b 和他的值
        qDebug() << mapCI;
        mapCI.insert('c',4);
        qDebug() << mapCI.take('c'); //移除键c,返回它的值
     
        //改
        mapCI.insert('a',2); //会覆盖同一个键的值,作用等同修改
     
        //查找
        QMap<char,int>::iterator it = mapCI.find('a');
        qDebug() << it.key() << it.value();
        mapCI.insert('b',2);
        qDebug() << mapCI.key(2); //返回该值得键,只返回一个键
        qDebug() << mapCI.keys(2); //返回该值得所有的键
        //返回键的链表
        QList<char> list = mapCI.uniqueKeys();
        qDebug() << list;
        //返回值得链表
        QList<int> list1 = mapCI.values();
        qDebug() << list1;
     
        //返回大小最接近b键的迭代器,从左到右
        it = mapCI.lowerBound('b');
        qDebug() << it.key() << it.value();
        //返回大小最接近b(不包括b)键的迭代器,从右到左
        it = mapCI.upperBound('b');
        qDebug() << it.key() << it.value();
        qDebug() << mapCI.contains('b');//如果含有b键,返回true
        //查找返回迭代器指针或者 end
        qDebug() << mapCI.constFind('b').value();
     
        //转换
        std::map<char,int> map = mapCI.toStdMap();
        return a.exec();
    }
    

    ————————————————
    版权声明:本文为CSDN博主「Liu_Xiao_Ming」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/Liu_Xiao_Ming/article/details/103395470

    更多相关内容
  • QMAP-用C ++编写的用于量子电路映射的JKQ工具 基于 , 提出的方法,提供了一种用于量子电路映射的工具。 A. Zulehner,A。Paler和R. Wille。 “将量子电路映射到IBM QX体系结构的有效方法” 。 IEEE集成电路和系统...
  • QMAP改写的简易CMAP类
  • Qt容器类比较典型的就是QList,QMap,遍历器的使用分为STL风格和Java风格。
  • python库。 资源全名:jkq.qmap-1.2.1.tar.gz
  • QMap 键值存储

    2021-05-16 11:15:32
    Qt中的QMap介绍与使用,在坛子里逛了一圈,发现在使用QMap中,出现过很多的问题,Map是一个很有用的数据结构。它以“键-值”的形式保存数据。在使用的时候,通过提供字符标示(键)即可得到想要的数据。这个“数据”即...

    Qt中的QMap介绍与使用,在坛子里逛了一圈,发现在使用QMap中,出现过很多的问题,Map是一个很有用的数据结构。它以“键-值”的形式保存数据。在使用的时候,通过提供字符标示(键)即可得到想要的数据。这个“数据”即可以是一个字符串,也可以是任意对象,当然也包括自己定义的类对象。说明:map是以值传递的形式保存数据的。

    1. 基本应用

    下面以“键-值”都是QString的例子说明QMap的基本使用方法。更详细的说明,请查看《Qt帮助手册》或其他资源。

    #include

    #include

    usingnamespacestd;

    classMapTest

    {

    public:

    voidshowMap()

    {

    if(!m_map.isEmpty())return;//判断map是否为空

    m_map.insert("111","aaa");//向map里添加一对“键-值”

    if(!m_map.contains("222"))//判断map里是否已经包含某“键-值”

    m_map.insert("222","bbb");

    m_map["333"] ="ccc";//另一种添加的方式

    qDebug("map[333] , value is : "+ m_map["333"]);//这种方式既可以用于添加,也可以用于获取,但是你必须知道它确实存在

    if(m_map.contains("111")){

    QMap::iterator it = m_map.find("111");//找到特定的“键-值”对

    qDebug("find 111 , value is : "+ it.data());//获取map里对应的值

    }

    cout<

    qDebug("size of this map is : %d", m_map.count());//获取map包含的总数

    cout<

    QMap::iterator it; //遍历map

    for( it = m_map.begin(); it != m_map.end(); ++it ) {

    qDebug( "%s: %s", it.key().ascii(), it.data().ascii());//用key()和data()分别获取“键”和“值”

    }

    m_map.clear(); //清空map

    }

    private:

    QMap m_map; //定义一个QMap对象

    };

    #include

    #include

    using namespace std;

    class MapTest

    {

    public:

    void showMap()

    {

    if(!m_map.isEmpty()) return; //判断map是否为空

    m_map.insert("111", "aaa"); //向map里添加一对“键-值”

    if(!m_map.contains("222")) //判断map里是否已经包含某“键-值”

    m_map.insert("222", "bbb");

    m_map["333"] = "ccc"; //另一种添加的方式

    qDebug("map[333] , value is : " + m_map["333"]); //这种方式既可以用于添加,也可以用于获取,但是你必须知道它确实存在

    if(m_map.contains("111")){

    QMap::iterator it = m_map.find("111"); //找到特定的“键-值”对

    qDebug("find 111 , value is : " + it.data()); //获取map里对应的值

    }

    cout<< endl;

    qDebug("size of this map is : %d", m_map.count()); //获取map包含的总数

    cout<< endl;

    QMap::iterator it; //遍历map

    for ( it = m_map.begin(); it != m_map.end(); ++it ) {

    qDebug( "%s: %s", it.key().ascii(), it.data().ascii()); //用key()和data()分别获取“键”和“值”

    }

    m_map.clear(); //清空map

    }

    private:

    QMap m_map; //定义一个QMap对象

    };

    调用类函数showMap(),显示结果:

    map[333] , value is : ccc

    find 111 , value is : aaa

    size of thismap is : 3

    111: aaa

    222: bbb

    333: ccc

    map[333] , value is : ccc

    find 111 , value is : aaa

    size of this map is : 3

    111: aaa

    222: bbb

    333: ccc

    2. 对象的使用

    map当中还可以保存类对象、自己定义类对象,例子如下(摘自QT帮助文档《Qt Assistant》,更详细的说明参考之):

    以注释形式说明

    #include

    #include

    #include

    //自定义一个Employee类,包含fn、sn、sal属性

    classEmployee

    {

    public:

    Employee(): sn(0) {}

    Employee( constQString& forename,constQString& surname,intsalary )

    : fn(forename), sn(surname), sal(salary)

    { }

    QString forename() const{returnfn; }

    QString surname() const{returnsn; }

    intsalary()const{returnsal; }

    voidsetSalary(intsalary ) { sal = salary; }

    private:

    QString fn;

    QString sn;

    intsal;

    };

    intmain(intargc,char**argv)

    {

    QApplication app( argc, argv );

    typedefQMap EmployeeMap;//自定义一个map类型,值为EmployeeMap对象

    EmployeeMap map;

    map["JD001"] = Employee("John","Doe", 50000);//向map里插入键-值

    map["JW002"] = Employee("Jane","Williams", 80000);

    map["TJ001"] = Employee("Tom","Jones", 60000);

    Employee sasha( "Sasha","Hind", 50000 );

    map["SH001"] = sasha;

    sasha.setSalary( 40000 ); //修改map值的内容,因为map采用值传递,所以无效

    //批量打印

    EmployeeMap::Iterator it;

    for( it = map.begin(); it != map.end(); ++it ) {

    printf( "%s: %s, %s earns %d\n",

    it.key().latin1(),

    it.data().surname().latin1(),

    it.data().forename().latin1(),

    it.data().salary() );

    }

    return0;

    }

    #include

    #include

    #include

    //自定义一个Employee类,包含fn、sn、sal属性

    class Employee

    {

    public:

    Employee(): sn(0) {}

    Employee( const QString& forename, const QString& surname, int salary )

    : fn(forename), sn(surname), sal(salary)

    { }

    QString forename() const { return fn; }

    QString surname() const { return sn; }

    int salary() const { return sal; }

    void setSalary( int salary ) { sal = salary; }

    private:

    QString fn;

    QString sn;

    int sal;

    };

    int main(int argc, char **argv)

    {

    QApplication app( argc, argv );

    typedef QMap EmployeeMap; //自定义一个map类型,值为EmployeeMap对象

    EmployeeMap map;

    map["JD001"] = Employee("John", "Doe", 50000); //向map里插入键-值

    map["JW002"] = Employee("Jane", "Williams", 80000);

    map["TJ001"] = Employee("Tom", "Jones", 60000);

    Employee sasha( "Sasha", "Hind", 50000 );

    map["SH001"] = sasha;

    sasha.setSalary( 40000 ); //修改map值的内容,因为map采用值传递,所以无效

    //批量打印

    EmployeeMap::Iterator it;

    for ( it = map.begin(); it != map.end(); ++it ) {

    printf( "%s: %s, %s earns %d\n",

    it.key().latin1(),

    it.data().surname().latin1(),

    it.data().forename().latin1(),

    it.data().salary() );

    }

    return 0;

    }

    Program output:

    JD001: Doe, John earns 50000

    JW002: Williams, Jane earns 80000

    SH001: Hind, Sasha earns 50000

    TJ001: Jones, Tom earns 60000

    展开全文
  • QMapIterator 类 QMapIterator 类 为 QMap 类 以及 QMultiMap类 提供Java风格的常亮迭代器。 QMap既有java风格迭代器又有STL风格迭代器。java风格比STL风格的迭代器更高级也更容易使用;另一方面,java风格迭代器...

    QPair:

    QPair 就和 C++ 里的 Pair 用法差不多.

    Pair类型概述
    pair是一种模板类型,其中包含两个数据值,两个数据的类型可以不同,基本的定义如下:
    pair<int, string> a;
    表示a中有两个类型,第一个元素是int型的,第二个元素是string类型的,如果创建pair的时候没有对其进行初始化,则调用默认构造函数对其初始化。

    typedef pair<string, string> author;
    author pro("May", "Lily");
    author joye("James", "Joyce");
    

    类模板:
    template <class T1, class T2> struct pair
    参数:class T1是第一个值的数据类型,class T2是第二个值的数据类型。
    功能:pair将一对值(可以是不同的数据类型)组合成一个值,两个值可以分别用pair的两个公有函数first和second访问。
    具体用法:

    pair<int,string>p1;
    //使用默认构造函数
    pair<int,double>p2(1,2.4);
    //用给定值初始化
    pair<int,double>p3(p2);
    //拷贝构造函数
    

    2、通过pair的两个公有函数first和second访问两个元素

    pair<int,double>p1;
    p1.first=1;
    p1.second=2.4;
    cout<<p1.first<<endl;
    

    3、赋值(make_pair,变量间赋值,生成新的pair对象 )

    //make_pair
    pair<int,double>p1;
    p1=make_pair(1,2.4);
    
    //变量间赋值
    pair<int ,double>p1(1,2.4);
    pair<int,double>p2=p1;
    
    //生成新的pair对象 
    //可以使用make_pair对已存在的两个数据构造一个新的pair类型 
    int a=1;
    string b="sddgds";
    pair<int ,string>c;
    c=make_pair(a,b);
    

    QMap

    QMap是Qt的一个模板类,它是基于红黑树算法的一套字典。
    QMap<Key,T>是Qt容器类型的一种,它通过(Key, value)存储一对值,并通过Key可以查找与之关联的value的值。

    /* 创建QMap实例, 第一个参数为QString类型的键,第二个参数为int类型的值 */
        QMap<QString, int> map;
    
    /* 插入数据 两种方式*/
        map["math"] = 100;
        map.insert("English", 99);
       //打印输出: QMap((“English”, 99)(“math”, 100))
       
    /* 移除数据 */
        map.remove("math");
        //打印输出:QMap((“English”, 99))
    
    /* 遍历数据 (先随便插入几个)*/
        map.insert("Math", 100);
        map.insert("Chinese", 98);
        map.insert("physical", 97);
        map.insert("chemical", 96);
        map.insert("biological", 95);
        
    /* 遍历数据要使用迭代器,QT提供了两种方式的迭代 */
        /* 第一种是Java类型的迭代 */
        QMapIterator<QString, int> iterator(map);
        while (iterator.hasNext()) {
            iterator.next();
            qDebug() << iterator.key() << ":" << iterator.value();
        }
    
        /* 第二种是STL类型的迭代 */
        QMap<QString, int>::const_iterator iterator_1 = map.constBegin();
        while (iterator_1 != map.constEnd()) {
            qDebug() << iterator_1.key() << ":" << iterator_1.value();
            ++iterator_1;
        }
    	/*打印输出:两种方法输出一样
    	“Chinese” : 98
    	“English” : 99
    	“Math” : 100
    	“biological” : 95
    	“chemical” : 96
    	“physical” : 97*/
    /*由键查找对应键值*/
    	map.value("Math");
    /*由键值查找键*/
    	map.key(100);
    /*修改键值*/
        /* 通常一个键只对应一个值,如果再次调用insert()方法,会覆盖以前的值 */
        map.insert("Math", 120);
    /*查找是否包含某个键*/
    	bool isok = map.contains("Math");
    /*获取所有的键*/
    	QList<int> allKeys = map.values();
    /*获取所有的键值*/
    	QList<int> allValues = map.values();
    /*1键对应多值*/
        /* 使用QMultiMap类来实例化一个QMap对象 */
        QMultiMap<QString, QString> multiMap;
        multiMap.insert("People", "Name");
        multiMap.insert("People", "Gender");
        multiMap.insert("People", "Age");
        multiMap.insert("People", "Height");
        multiMap.insert("People", "Weight");
    

    QMapIterator 类

    QMapIterator 类 为 QMap 类 以及 QMultiMap类 提供Java风格的常亮迭代器。

    QMap既有java风格迭代器又有STL风格迭代器。java风格比STL风格的迭代器更高级也更容易使用;另一方面,java风格迭代器效率略低。

    QMapIterator<Key, T> 允许你对 QMap 或者 QMultiMap进行迭代。(所谓了迭代,说白了就是对一个 QMap类的容器进行一定顺序的遍历,可以看到里面的每一个内容(内容可以是QMap类的首地址等))。

    如果希望在迭代时修改该映射内容,请使用QMutableMapIterator类。

    QMapIterator构造函数用QMap 作为参数。在构造之后,迭代器定位在映射的最开始(在第一个项目之前)。下面是迭代器如何顺序遍历所有元素的:

    QMap<int, QWidget *> map;
    QMapIterator<int, QWidget *> i(map);
    while (i.hasNext()) {
        i.next();
        qDebug() << i.key() << ": " << i.value();
    }
    

    next() 返回映射中下一个项目 并且向前推进一步迭代器。 key() and value() 返回被跳过的最近项目的键和值。在这里插入图片描述
    遍历方式可以查看上面QMap中提到的两种迭代方式的代码。

    注:
    可以在同一映射上使用多个迭代器。如果在QMapIterator活动时映射被修改,QMapIterator将继续在原始映射上迭代,忽略修改后的副本

    展开全文
  • The QMap class is a value-based template class that providesa dictionary.More…#include List of all member functions.Public Memberstypedef Keykey_typetypedef Tmapped_typetypedef QPairvalue_typetypedef...

    The QMap class is a value-based template class that provides

    a dictionary.

    More…

    #include

    List of all member functions.

    Public Members

    typedef Keykey_type

    typedef Tmapped_type

    typedef QPairvalue_type

    typedef value_type*pointer

    typedef constvalue_type*const_pointer

    typedef value_type&reference

    typedef constvalue_type&const_reference

    typedef size_tsize_type

    typedef QMapIteratoriterator

    typedef QMapConstIteratorconst_iterator

    typedef QPairinsert_pair

    QMap ()

    QMap ( constQMap&m )

    QMap ( conststd::map&m )

    ~QMap ()

    QMap & operator= ( constQMap&m )

    QMap & operator= ( conststd::map&m )

    iterator begin ()

    iterator end ()

    const_iterator begin () const

    const_iterator end () const

    iterator replace ( constKey&k, constT&v )

    size_type size () const

    bool empty () const

    QPair insert ( constvalue_type&x )

    void erase ( iteratorit )

    void erase ( constkey_type&k )

    size_type count ( constkey_type&k ) const

    T & operator[] ( constKey&k )

    void clear ()

    typedef QMapIteratorIterator

    typedef QMapConstIteratorConstIterator

    typedef TValueType

    iterator find ( constKey&k )

    const_iterator find ( constKey&k ) const

    const T & operator[] ( constKey&k ) const

    bool contains ( constKey&k ) const

    size_type count () const

    QValueList keys () const

    QValueList values () const

    bool isEmpty () const

    iterator insert ( constKey&key, constT&value, booloverwrite = TRUE )

    void remove ( iteratorit )

    void remove ( constKey&k )

    Protected Members

    void detach ()

    Related Functions

    QDataStream & operator>> ( QDataStream&s, QMap&m )

    QDataStream & operator<< ( QDataStream&s, constQMap&m )

    Detailed Description

    The QMap class is a value-based template class that provides

    a dictionary.

    QMap is a Qt implementation of an STL-like map container. It

    can be used in your application if the standard map is not

    available. QMap is part of the Qt Template

    Library.

    QMap defines a template instance to create a

    dictionary with keys of type Key and values of type Data. QMap does

    not store pointers to the members of the map; instead, it holds a

    copy of every member. For that reason, QMap is value-based, whereas

    QPtrList and QDict are pointer-based.

    QMap contains and manages a collection of objects of type Data with

    associated key values of type Key and provides iterators that allow

    the contained objects to be addressed. QMap owns the contained

    items.

    Some classes cannot be used within a QMap. For example everything

    derived from QObject and thus all classes that implement widgets.

    Only values can be used in a QMap. To qualify as a value, the class

    must provide

    A copy constructor

    An assignment operator

    A default constructor, i.e. a constructor that does not take any arguments.

    Note that C++ defaults to field-by-field assignment operators and

    copy constructors if no explicit version is supplied. In many cases,

    this is sufficient.

    The class used for the key requires that the operator< is implemented

    to define ordering of the keys.

    QMap’s function naming is consistent with the other Qt classes

    (e.g., count(), isEmpty()). QMap also provides extra functions for

    compatibility with STL algorithms, such as size() and empty().

    Programmers already familiar with the STL map can use these

    functions instead.

    Example:

    #include

    #include

    #include

    class Employee

    {

    public:

    Employee(): sn(0) {}

    Employee( const QString& forename, const QString& surname, int salary )

    : fn(forename), sn(surname), sal(salary)

    { }

    QString forename() const { return fn; }

    QString surname() const { return sn; }

    int salary() const { return sal; }

    void setSalary( int salary ) { sal = salary; }

    private:

    QString fn;

    QString sn;

    int sal;

    };

    int main(int argc, char **argv)

    {

    QApplication app( argc, argv );

    typedef QMap EmployeeMap;

    EmployeeMap map;

    map["JD001"] = Employee("John", "Doe", 50000);

    map["JD002"] = Employee("Jane", "Williams", 80000);

    map["TJ001"] = Employee("Tom", "Jones", 60000);

    Employee sasha( "Sasha", "Hind", 50000 );

    map["SH001"] = sasha;

    sasha.setSalary( 40000 );

    EmployeeMap::Iterator it;

    for ( it = map.begin(); it != map.end(); ++it ) {

    printf( "%s: %s, %s earns %d\n",

    it.key().latin1(),

    it.data().surname().latin1(),

    it.data().forename().latin1(),

    it.data().salary() );

    }

    return 0;

    }

    Program output:

    JD001: Doe, John earns 50000

    JW002: Williams, Jane earns 80000

    SH001: Hind, Sasha earns 50000

    TJ001: Jones, Tom earns 60000

    The latest changes to Sasha’s salary did not affect the value in

    the list because the map created a copy of Sasha’s entry. In

    addition, notice that the items are sorted alphabetically (by key)

    when iterating over the map.

    There are several ways to find items in a map. The begin() and

    end() functions return iterators to the beginning and end of the

    map. The advantage of using an iterator is that you can move

    forward or backward by incrementing/decrementing the iterator. The

    iterator returned by end() points to the element which is one past

    the last element in the container. The past-the-end iterator is

    still associated with the map it belongs to, however it is not

    dereferenceable; operator*() will not return a well-defined value.

    If the map is empty, the iterator returned by begin() will equal

    the iterator returned by end().

    Another way to find an element in the map is by using the find()

    function. This returns an iterator pointing to the desired

    item or to the end() iterator if no such element exists.

    Another approach uses the operator[]. But be warned: if the map does

    not contain an entry for the element you are looking for, operator[]

    inserts a default value. If you do not know that the element you

    are searching for is really in the list, you should not use

    operator[]. The following example illustrates this:

    QMap map;

    map["Clinton"] = "Bill";

    str << map["Clinton"] << map["Bush"] << endl;

    The code fragment will print out “Clinton”, “”. Since the value

    associated with the “Bush” key did not exist, the map inserted a

    default value (in this case, an empty string). If you are not

    sure whether a certain element is in the map, you should use find()

    and iterators instead.

    If you just want to know whether a certain key is contained in the

    map, use the contains() function. In addition, count() tells you how

    many keys there are currently in the map.

    It is safe to have multiple iterators at the same time. If some

    member of the map is removed, only iterators pointing to the removed

    member become invalid; inserting in the map does not invalidate any

    iterators.

    Since QMap is value-based, there is no need to be concerned about deleting

    items in the map. The map holds its own copies and will free

    them if the corresponding member or the map itself is deleted.

    QMap is implicitly shared. This means you can just make copies of

    the map in time O(1). If multiple QMap instances share the same data

    and one is modifying the map’s data, this modifying instance

    makes a copy and modifies its private copy; it thus does not affect

    other instances. From a developer’s point of view you can think

    that a QMap and a copy of this map have nothing to do with each

    other. If a QMap is being used in a multi-threaded program, you must

    protect all access to the map. See QMutex.

    There are several ways of inserting new items into the map. One

    uses the insert() method; the other one uses operator[] like this:

    QMap map;

    map["Clinton"] = "Bill";

    map.insert( qMakePair("Bush", "George") );

    Items can also be removed from the map in several ways. The first is

    to pass an iterator to remove(). The other is to pass a key

    value to remove(), which will delete the entry with the requested

    key. In addition you can clear the entire map using the clear()

    method.

    See also QMapIterator, Qt Template Library Classes, Implicitly and Explicitly Shared Classes and Non-GUI Classes.

    Member Type Documentation

    QMap::ConstIterator

    The map’s const iterator type, Qt style.

    QMap::Iterator

    The map’s iterator type, Qt style.

    QMap::ValueType

    Corresponds to QPair, Qt style.

    QMap::const_iterator

    The map’s const iterator type.

    QMap::const_pointer

    Const pointer to value_type.

    QMap::const_reference

    Const reference to value_type.

    QMap::iterator

    The map’s iterator type.

    QMap::key_type

    The map’s key type.

    QMap::mapped_type

    The map’s data type.

    QMap::pointer

    Pointer to value_type.

    QMap::reference

    Reference to value_type.

    QMap::size_type

    An unsigned integral type, used to represent various sizes.

    QMap::value_type

    Corresponds to QPair.

    Member Function Documentation

    QMap::QMap ()

    Constructs an empty map.

    QMap::QMap ( constQMap&m )

    Constructs a copy of m.

    This operation costs O(1) time because QMap is implicitly shared. The

    first instance of applying modifications to a shared map will create a

    copy that takes in turn O(n) time. However, returning a QMap from a

    function is very fast.

    QMap::QMap ( conststd::map&m )

    Constructs a copy of m.

    QMap::~QMap ()

    Destroys the map. References to the values in the map and all

    iterators of this map become invalidated. Since QMap is highly tuned

    for performance you won’t see warnings if you use invalid iterators,

    because it is not possible for an iterator to check whether it is

    valid or not.

    iterator QMap::begin ()

    Returns an iterator pointing to the first element in the map. This

    iterator equals end() if the map is empty.

    The items in the map are traversed in the order defined by

    operator

    See also end() and QMapIterator.

    const_iterator QMap::begin () const

    This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

    See also end() and QMapConstIterator.

    void QMap::clear ()

    Removes all items from the map.

    See also remove().

    bool QMap::contains ( constKey&k ) const

    Returns TRUE if the map contains an item with key k; otherwise

    returns FALSE.

    size_type QMap::count ( constkey_type&k ) const

    Returns the number of items whose key is k. Since QMap does

    not allow duplicate keys, the return value is always 0 or 1.

    This function is provided for STL compatibility.

    size_type QMap::count () const

    This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

    Returns the number of items in the map.

    See also isEmpty().

    void QMap::detach () [protected]

    If the map does not share its data with another QMap instance,

    nothing happens; otherwise the function creates a new copy of this

    map and detaches from the shared one. This function is called

    whenever the map is modified. The implicit sharing mechanism is

    implemented this way.

    bool QMap::empty () const

    Returns TRUE if the map contains zero items; otherwise returns FALSE.

    This function is provided for STL compatibility. It is equivalent

    to isEmpty().

    See also size().

    iterator QMap::end ()

    The iterator returned by end() points to the element which is one

    past the last element in the container. The past-the-end iterator

    is still associated with the map it belongs to, however it is not dereferenceable; operator*() will not return a well-defined

    value.

    This iterator equals begin() if the map is empty.

    See also begin() and QMapIterator.

    const_iterator QMap::end () const

    This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

    The iterator returned by end() points to the element which is one

    past the last element in the container. The past-the-end iterator

    is still associated with the map it belongs to, however it is not dereferenceable; operator*() will not return a well-defined

    value.

    This iterator equals begin() if the map is empty.

    See also begin() and QMapConstIterator.

    void QMap::erase ( iteratorit )

    Removes the item associated with the iterator it from the map.

    This function is provided for STL compatibility. It is equivalent

    to remove().

    See also clear().

    void QMap::erase ( constkey_type&k )

    This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

    Removes the item with the key k from the map.

    iterator QMap::find ( constKey&k )

    Returns an iterator pointing to the element with key k in the map.

    Returns end() if no key matched.

    See also QMapIterator.

    const_iterator QMap::find ( constKey&k ) const

    This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

    Returns an iterator pointing to the element with key k in the map.

    Returns end() if no key matched.

    See also QMapConstIterator.

    iterator QMap::insert ( constKey&key, constT&value, booloverwrite = TRUE )

    Inserts the value with key. If there is already a value

    associated with key, it is replaced, unless overwrite is

    FALSE (it is TRUE by default).

    QPair QMap::insert ( constvalue_type&x )

    This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

    Inserts the (key, value) pair x into the map. x is a QPair

    whose first element is a key to be inserted and whose second

    element is the associated value to be inserted. Returns a pair

    whose first element is an iterator pointing to the inserted item

    and whose second element is a bool indicating TRUE if x was

    inserted and FALSE if it was not inserted because it was already

    present.

    bool QMap::isEmpty () const

    Returns TRUE if the map contains zero items; otherwise returns FALSE.

    See also count().

    QValueList QMap::keys () const

    Returns a list of all the keys in the map.

    QMap& QMap::operator= ( constQMap&m )

    Assigns m to this map and returns a reference to this map.

    All iterators of the current map become invalidated by this

    operation. The cost of such an assignment is O(1), because QMap is

    implicitly shared.

    QMap& QMap::operator= ( conststd::map&m )

    This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

    Assigns m to this map and returns a reference to this map.

    All iterators of the current map become invalidated by this

    operation.

    T & QMap::operator[] ( constKey&k )

    Returns the value associated with the key k. If no such

    key is present, an empty item is inserted with this key

    and a reference to the item is returned.

    You can use this operator both for reading and writing:

    QMap map;

    map["Clinton"] = "Bill";

    stream << map["Clinton"];

    const T & QMap::operator[] ( constKey&k ) const

    This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

    Warning: This function differs from the non-const version of the

    same function. It will not insert an empty value if the key k

    does not exist. This may lead to logic errors in your program. You

    should check if the element exists before calling this function.

    Returns the value associated with the key k. If no such

    key is present, a reference to an empty item is returned.

    void QMap::remove ( iteratorit )

    Removes the item associated with the iterator it from the map.

    See also clear().

    void QMap::remove ( constKey&k )

    This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

    Removes the item with the key k from the map.

    iterator QMap::replace ( constKey&k, constT&v )

    Replaces the value with key k from the map if possible, and

    inserts the new value v with key k in the map.

    See also insert() and remove().

    size_type QMap::size () const

    Returns the number of items in the map.

    This function is provided for STL compatibility. It is equivalent

    to count().

    See also empty().

    QValueList QMap::values () const

    Returns a list of all the values in the map.

    Related Functions

    QDataStream& operator<< ( QDataStream&s, constQMap&m )

    Writes the map m to the stream s. The types Key and T

    must implement the streaming operator as well.

    QDataStream& operator>> ( QDataStream&s, QMap&m )

    Reads the map m from the stream s. The types Key and T

    must implement the streaming operator as well.

    展开全文
  • QMap详解

    万次阅读 多人点赞 2020-11-05 10:00:34
    QMap详解 QMap是Qt的一个模板类,它是基于红黑树算法的一套字典。 QMap<Key,T>是Qt容器类型的一种,它通过(Key, value)存储一对值,并通过Key可以查找与之关联的value的值。 QMap和 QHash是很相似的,不同的...
  • [QT] QMap使用详解

    千次阅读 2021-04-20 10:24:43
    [QT] QMap使用详解 一. 目录 1. 实例化QMap对象 2. 插入数据 3. 移除数据 4. 遍历数据 5. 由键查找对应键值 6. 由键值查找键 7. 修改键值 8. 查找是否包含某个键 9. 获取所有的键和键值 10. 一个键对应多个值 1. ...
  • QMap 和 QHash容器

    千次阅读 2022-03-28 21:40:56
    QMap类、 QHash类 QMap与QHash差别: ①QHash比QMap查找速度更快。 ②QHash以任意顺序存储,QMap以Key顺序存储数据。 ③QHash的Key必须提供operator==()及一个全局的qHash(Key)函数,而QMap的Key必须提供operator&...
  • Qt6STL-QMap分析

    2021-12-13 10:52:10
    文章目录简介QMap添加头文件QMap添加QMap遍历QMap查找QMap删除QMap综合例子 简介 QMap是Qt的一个模板类,它是基于红黑树算法的一套字典。 QMap<Key,T>是Qt容器类型的一种,它通过(Key, value)存储一对值,并...
  • Qt容器:QMap

    千次阅读 2021-07-24 17:42:06
    QMap<Key, T> 是 Qt 的通用容器类之一。 它存储(键,值)对并提供按键快速查找。 二、成员函数 1、QMap::const_iterator constFind(const Key &key) 返回一个 const 迭代器,该迭代器指向map中具有 ...
  • QMap > tmp_map; QMap tmp_point; for (int i = 4; i ()-4; i++) { QPointF pos0 = m_PolygonPoints[i]; QPointF pos1 = m_PolygonPoints[i-4]; QPointF pos2 = m_PolygonPoints[i+4]; x1 = pos1.x(); y1 = pos1.y...
  • 一文总结Qt关联式容器类—QMap 一、开篇 ​ QMap是一个模板类,它提供了一个基于红黑树的字典。QMap<Key, T>是Qt的一个通用容器类。它存储(键、值)对,并提供与键关联的值的快速查找方法。 ​ ​ QMap和QHash...
  • QMap map; map.insert(MyKey("10086", 0), "value1"); map.insert(MyKey("10086", 1), "value2"); map.insert(MyKey("10086", 2), "value3"); map.insert(MyKey("10010", 1), "value4"); map.insert(MyKey("10010",...
  • qmap合并

    2021-12-06 15:09:26
    用insert,如果key有重复的会覆盖
  • Qt之QMap的使用分析

    2022-06-27 13:50:55
    5.保证无毒 1.简单,方便,实用 3.实例可以自行改用 1.如有非法,本人无法律责任! 8.更多作品,查找标签“朱建强”7.... 4.如需联系我请看左边数字!1.如不知代表何物,那就放弃计算机吧! 0....CSDN老板不让我上传联系方式。
  • QMap中的数据全都放到QString中,包括符号,我这里使用大括号来代替原本的小括号(因为我太怀念python的字典了),用中文的双引号代替原本英文的双引号,这样就实现从QMap到QString的转换;从QString到QMap,其实...
  • QMap获取所有key和value

    2022-06-01 17:15:12
    根据Qmap的迭代器获取key和value
  • QMapIterator> #include <QMutableMapIterator> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QMap<QString, QString> map;
  • QT QMap QMultiMap使用说明

    千次阅读 2020-12-11 17:25:59
    QMap<Key, T>: 它提供了一个字典(关联数组),将Key类型的键值映射到T类型的值上。一般每一个键关联单一的值。QMap使用键顺序来存储它的数据;如果不关心存储顺序,那么可以使用QHash来代替它,因为QHash...
  • QMap常用用法

    千次阅读 2021-07-08 17:37:16
    QMap的常用函数 1. iterator QMap::erase(iterator pos) 从映射中移除迭代器pos指向的(键、值)对,并将迭代器返回到映射中的下一项。 2. int QMap::remove(const Key &key) 从映射中删除所有具有密钥的项。...
  • QMap<QString,QByteArray> m_qMap; 2——插入赋值,QMap只允许每个键有一个值。如果使用QMap中已存在的键调用Insert(),则先前的值将被擦除。 //方式一 m_qMap["one"] = "1"; m_qMap["three"] = "2"; m...
  • QMap< int, struct2 >怎么序列化啊?key值是int型,value值是struct2型,好像不能直接序列化???有没有什么方法将这种情况序列化啊?</p>

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 4,729
精华内容 1,891
关键字:

QMAP

友情链接: 波形比较.rar