Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use QVector(Qt) instead of std::vector

Tags:

c++

vector

qt

I'm very new to C++ and Qt, but I'm very good at C#/Java.

The point is I like cross-platform, but I'm confuse with Qt. Isn't std::vector already cross-platform, doesn't Qt provide an equivalent to a non-crossplatform thing?

Also how are File and QFile different?

A link would be nice, thanks :)

like image 241
Athiwat Chunlakhan Avatar asked Apr 11 '11 14:04

Athiwat Chunlakhan


People also ask

What is the difference between QList and QVector?

QVector is mostly analogous to std::vector , as you might guess from the name. QList is closer to boost::ptr_deque , despite the apparent association with std::list . It does not store objects directly, but instead stores pointers to them.

Should I use std for vector?

As a rule of thumb, you should use: a std::array if the size in fixed at compile time. a std::vector is the size is not fixed at compile time. a pointer on the address of their first element is you need low level access.

Is std::vector fast?

A std::vector can never be faster than an array, as it has (a pointer to the first element of) an array as one of its data members. But the difference in run-time speed is slim and absent in any non-trivial program. One reason for this myth to persist, are examples that compare raw arrays with mis-used std::vectors.

What is a QVector?

The QVector class is a template class that provides a dynamic array.


1 Answers

This article loooks good. It compares Qt Template Library with Standard Template Library:

  • QTL vs STL

Hope, you'll find it interesting seeing all the differences listed there in the article.

EDIT:

Here is what I find interesting:

My opinion is that the biggest advantage of the QTL is that it has the same implementation (including binary compatibility) on all OSes supported by Qt. Some STL implementations might be below par when it comes to performance or they might be missing functionality. Some platforms don’t even have an STL! On the other hand, the STL is more customizable and is available in its entirety in header files… Like I said, there is no clear winner.

Like he said, no clear winner. But still reading the article makes lots of things clear. Its better to know the difference than going for one, without knowing the other.

like image 145
Nawaz Avatar answered Sep 18 '22 08:09

Nawaz