Questions tagged [qvector]

The QVector class, part of the Qt framework, is a template class that provides a dynamic array.

QVector<T> is one of Qt's generic container classes. It stores its items in adjacent memory locations and provides fast index-based access.

The official Qt documentation can be found here for Qt 4.8 and here for Qt 5.

172 questions
24
votes
2 answers

Why QVector::size returns int?

std::vector::size() returns a size_type which is unsigned and usually the same as size_t, e.g. it is 8 bytes on 64bit platforms. In constrast, QVector::size() returns an int which is usually 4 bytes even on 64bit platforms, and at that it is signed,…
user3735658
23
votes
8 answers

QList vs QVector revisited

My question is basically when to choose QVector and when to choose QList as your Qt container. What I already know: Qt docs: QList class For most purposes, QList is the right class to use. Its index-based API is more convenient than QLinkedList's…
demonplus
  • 5,613
  • 12
  • 49
  • 68
15
votes
1 answer

Why do Qt's container classes not allow movable, non-copyable element types?

The Qt container classes QList, QVector etc. require their element types to be copyable. Since C++11, the STL containers require their element type to be copyable or movable only. Why do the Qt containers not support move-only element types?
Ralph Tandetzky
  • 22,780
  • 11
  • 73
  • 120
12
votes
3 answers

How to initialize QVector

I am new to c++ and Qt and I am trying to initialize a QVector, which is a class member in a class initialization list like: MyClass::MyClass(QWidget *parent) : QMainWindow(parent) , myVector(QVector(100)) I was expecting the QVector to…
Michel Feinstein
  • 13,416
  • 16
  • 91
  • 173
7
votes
1 answer

What is the reason of QVector's requirement for default constructor?

I can see that that classes are treated as complex objects which are required for calling default constructor: void QVector::defaultConstruct(T *from, T *to) { if (QTypeInfo::isComplex) { while (from != to) { new…
Grief
  • 1,839
  • 1
  • 21
  • 40
5
votes
2 answers

No matching call to default constructor, when using QVector

I have a class B that creates an object of a class A and calls a method of the object. a.h #ifndef A_H #define A_H class A { public: A(int); void function(); }; #endif // A_H a.cpp #include "a.h" A::A(int x) { } void A::function(){ …
Luca9984
  • 141
  • 6
5
votes
2 answers

QVector of struct - no appropriate default constructor available

I'm very confused as to why this isn't working. I must be misunderstanding something key about QVectors... I've created an MCVE to show the issue: #include #include struct ChunkRequest { ChunkRequest(int x, int z) …
mrg95
  • 2,371
  • 11
  • 46
  • 89
5
votes
2 answers

Remove all elements from QVector which are smaller than 0

I have a QVector QVector(48, 64, 31, -2, 14, 5, 7, -3, -1, 13) I want to know how to use Qt mechanism to remove all the elements that are smaller than 0. How do I do this in a simple way? Thanks
Theodore Tang
  • 831
  • 2
  • 21
  • 42
4
votes
1 answer

QCache and QSharedPointer

The problem is, that I have a QVector of QSharedPointer and I want to put part of them to my QCache. How can I insert a shared pointer to QCache? What happens if I set the pointer to my cache but destroy the QVector and the shared pointer in it?…
adapto
  • 95
  • 1
  • 12
4
votes
1 answer

Using Vectors with Qt

I seem to be having an issue using basic vectors in Qt, where I keep getting a compile error. The exact information will be posted below: Code snippet: .... #include #include QVector
Ruiz
  • 93
  • 2
  • 6
3
votes
3 answers

Importing OBJ file in QtCreator

I'm new in using Qt Creator (version 4.10.0, based on Qt 5.13.1). I have taken the customitemgraph example and I would like to replace the existing .obj files with new ones. I have downloaded some free models from the web. Some of these work but…
Sandra
  • 33
  • 4
3
votes
0 answers

What is the most efficient way to fill a QVector with data?

I use QLists all over my code. According to https://doc.qt.io/qt-5/qvector.html and the linked page http://marcmutz.wordpress.com/effective-qt/containers/ QVector "should always be the first choice", or one shouldn't use QList at all, as long as one…
Tobias Leupold
  • 1,512
  • 1
  • 16
  • 41
3
votes
2 answers

How to add items from multiple QStringLists to one?

If I have several QStringLists, for example: QStringList str1 = {"name1", "name2", "name3"}; QStringList str2 = {"value1", "value2", "value3"}; QStringList str3 = {"add1", "add2", "add3"}; Is there any way to get list of lists (nested list) like…
ImNew
  • 97
  • 9
3
votes
2 answers

C++ read-only struct that can be set from within a class?

I have a class Foo that has defined a public struct Data inside of it, with a QVector allData nesting multiple objects of the Data struct inside of it: class Foo { public: struct Data { uchar valueA; uchar…
ExtraGoofy
  • 41
  • 6
3
votes
1 answer

Sort QVector of pointers to custom objects

My Question: What is the best way to assign numbers to each Camera in a QVector where the following specifications should apply: The unsorted QVector should keep its order The int number of each Camera should be assigned depending on its…
chrizbee
  • 145
  • 1
  • 13
1
2 3
11 12