zoukankan      html  css  js  c++  java
  • QT容器类

    QList<T>

    是一个指针数组,可以使用下标

    append(), prepend(), insert()

    QList<QString> list;
    list<<"a"<<"b"<<"c";
    qDebug()<<list[0]; QList
    <QString>::iterator i; //定义读写迭代器 for(i=list.begin(); i!=list.end(); ++i) { qDebug()<<(*i); *i="x"; }

    QLinkedList<T>

    是一个链表,所以不能使用下标,只能使用迭代器访问数据项

    QVector<T>

    在相邻的内存中存储一组数值,在前部或中间插入数据是很慢的,需要移动后面的所有数据。

    既可以用下标,也可以用迭代器访问。子类有QPolygon, QPolygonF和QStack.

    QMap<key, T>

    QMap<QString, int> map;
    map.insert("beijing", 123);
    map.insert("shanghai", 456);
    map.insert("guangzhou", 789);
    QMap<QString, int>::const_iterator i;//只读迭代器
    for(i=map.constBegin(); i!=map.constEnd();++i)
    {
      qDebug()<<i.key()<<","<<i.value();  
    }
    QMap<QString, int>::iterator mi;//读写迭代器
    mi=map.find("beijing");
    if(mi!=map.end())
    {
      mi.value()=321;  
    }

    QMap与QHash比较

    QHash以任意顺序存储,QMap按key键顺序存储

    单次操作QMap快,多次操作QHash快

    QVariant

    QVariant v(709);//定义一个变量并初始化为709
    qDebug<<v.toInt();
    QVariant w("hello");
    qDebug<<w.toString();
    QMap<QString, QVariant>map;
    map["int"]=709;
    map["double"]=709.9;
    map["string"]="hello";
    map["color"]=QColor(255,0,0);
    qDebug()<<map["int"]<<map["int"].toInt();
  • 相关阅读:
    新·刷题记录【争取认真来做】
    Codeforces 235D Graph Game
    Codeforces 235B Let's Play Osu!
    Codeforces 235E Number Challenge
    Codeforces 235C Cyclical Quest
    AHOI2017游记
    bzoj4826: [Hnoi2017]影魔
    大数分解模板
    A new start
    0712
  • 原文地址:https://www.cnblogs.com/xieqianli/p/11386960.html
Copyright © 2011-2022 走看看