毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> 移动平台 >> 正文

qt 实现按下标存放数据源代码

更新时间:2013-3-1:  来源:毕业论文

qt 实现按下标存放数据源代码
现在我想实现在一个容器中存放固定数量的数据而且要按下标顺序存放,存放的是自定义对象,怎么实现?
用QList不就行了吗?你有啥子特殊要求? 毕业论文 
QVector
QList

如果是自定义对象 最好实现该对象的拷贝构造方法,因为在push到容器的时候,往往会调用其拷贝构造函数进行资源的拷贝,如果没有实现的话,按默认拷贝可能会有问题
下面是Qt的容器
As special cases, the QCache and QContiguousCache classes provide efficient hash-lookup of objects in a limited cache storage.

Class Summary
QList<T> This is by far the most commonly used container class. It stores a list of values of a given type (T) that can be accessed by index. Internally, the QList is implemented using an array, ensuring that index-based access is very fast.
Items can be added at either end of the list using QList::append() and QList::prepend(), or they can be inserted in the middle using QList::insert(). More than any other container class, QList is highly optimized to expand to as little code as possible in the executable. QStringList inherits from QList<QString>.
QLinkedList<T> This is similar to QList, except that it uses iterators rather than integer indexes to access items. It also provides better performance than QList when inserting in the middle of a huge list, and it has nicer iterator semantics. (Iterators pointing to an item in a QLinkedList remain valid as long as the item exists, whereas iterators to a QList can become invalid after any insertion or removal.)
QVector<T> This stores an array of values of a given type at adjacent positions in memory. Inserting at the front or in the middle of a vector can be quite slow, because it can lead to large numbers of items having to be moved by one position in memory.
QStack<T> This is a convenience subclass of QVector that provides "last in, first out" (LIFO) semantics. It adds the following functions to those already present in QVector: push(), pop(), and top().
QQueue<T> This is a convenience subclass of QList that provides "first in, first out" (FIFO) semantics. It adds the following functions to those already present in QList: enqueue(), dequeue(), and head().
QSet<T> This provides a single-valued mathematical set with fast lookups.
QMap<Key, T> This provides a dictionary (associative array) that maps keys of type Key to values of type T. Normally each key is associated with a single value. QMap stores its data in Key order; if order doesn't matter QHash is a faster alternative.
QMultiMap<Key, T> This is a convenience subclass of QMap that provides a nice interface for multi-valued maps, i.e. maps where one key can be associated with multiple values.
QHash<Key, T> This has almost the same API as QMap, but provides significantly faster lookups. QHash stores its data in an arbitrary order.
QMultiHash<Key, T> This is a convenience subclass of QHash that provides a nice interface for multi-valued hashes.

你可以采用QMap
插入的时候
实现你自定义对象的 bool operator < ()操作符重载,插入时会调用这个比较自定义对象,然后以RBT的方式将数据插入

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。