Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the equivalent std::deque in Qt?

Tags:

qt

deque

I am on several lines codes from a Qt project to appending into a Qvector every 1s. I noticed that in STL deque could have a better performance in adding a new element into the end that vector. What's the equivalent or similar Qt way? Cause I don't find any in Qt libraries.

Julio

like image 209
colddie Avatar asked May 14 '13 08:05

colddie


2 Answers

There is no direct equivalent to the std::deque class in QT.

However, your best bet is to use QList.

Here is what the documentation says about QT container classes:

For most purposes, QList is the right class to use. Its index-based API is more convenient than QLinkedList's iterator-based API, and it is usually faster than QVector because of the way it stores its items in memory. It also expands to less code in your executable.

Anyways, if you are only appending items once every second, there will not be much impact to choose one over the other.

like image 63
SirDarius Avatar answered Nov 11 '22 00:11

SirDarius


There is no need to have a Qt equivalent for every std container, you can use std::deque if that is what you are after.

Anyway, note that for the case when you do a lot of insertions at the end of the vector both std::vector and QVector have a member function named reserve (see the links) that can be used to pre-allocates a bigger buffer and make insertions at the end faster.

like image 22
Zlatomir Avatar answered Nov 11 '22 02:11

Zlatomir