Questions tagged [qmap]

QMap is a Qt container class that implements a map a.k.a. a skip-list-based dictionary.

This container looks like this:

QMap< Key, T >

It stores key-value pairs, and provides access to the value by the key and vice-versa. It also provides iterator-based access. A typical usage of the QMap is as follows:

//constructs a map with strings as keys and integers as values.
QMap< QString, int > myMap;
//this will set the value for the key "qwerty" if it doesn't exist, or override the current value if it does exist:
myMap["qwerty"] = 15;
//accessing elements is as easy as this:
int i = myMap["qwerty"];

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

189 questions
5
votes
2 answers

Default Value for qmap optional parameter

I'm working in C++ and want to create a function with an optional parameter that is a QMap. The question is what do I set the default value to. I want it to be an empty map. void function(int i, QMap< QString, QString > MyMap = ???) what do you…
user3685722
  • 91
  • 1
  • 5
5
votes
2 answers

QMap and std::unique_ptr

I am trying to prevent naked pointers, to prevent memory leaking etc. I also want to map int to INuiSensor*. Since I am also using Qt I tried to use QMap> to do this, but the source code of QMap makes this…
Cheiron
  • 3,620
  • 4
  • 32
  • 63
5
votes
2 answers

Unicode characters in qt app dont show up

I'm trying to display different language strings in my qt app by inserting each language into a QMap so it can be re-used in several places and put into different combo Boxes across the application. I do this by creating the QMap…
Tim
  • 647
  • 1
  • 10
  • 21
4
votes
2 answers

How to sort QMap?

I have a QMap with myStruct { QString firstname; QString lastname; QString status; } How can I sort this QMap according to priority order: status then firstname then lastname?
gnase
  • 580
  • 2
  • 10
  • 25
4
votes
1 answer

iterator expected to have different behaviour when calling next()/previous() on items

I have created a simple map and an iterator on it. When i move the iterator to next items, it performs well. After forwarding the iterator, if I ask it to go back for previous item and get value() of the iterator, it is not really the previous item…
Mosi
  • 1,178
  • 2
  • 12
  • 30
4
votes
1 answer

QMap::contains() not returning expected value

I have a class that contains a QMap object: QMap users; Now, in the following function Foo(), the if clause always returns false but when I iterate through the map, the compared QString, i.e., str1 is present in the keys.…
Saurabh Manchanda
  • 1,115
  • 1
  • 9
  • 21
4
votes
1 answer

QMap iterate foreach

Is it possible to iterate through qmap when key and value is a pointer with foreach? I always get the error: decltype cannot resolve address of overloaded function template bool func(T1* subject, QMap* map) { …
Ini
  • 548
  • 7
  • 19
4
votes
2 answers

QMap but without sorting by key

I need structure like QMap but without sorting on keys, so if I insert item there first I can count that this item will be before all others. And insert pair before or after specified element. Does Qt have such?
Borrimoro
  • 529
  • 3
  • 9
  • 19
4
votes
1 answer

QMap with pointer as key

I am using QMap and I have pointers to the object as keys of the map. Using std::map I would write a comparator for pointers and declare my map as follow std::map > How I have to do with QMap? I cannot find in…
user14416
  • 2,922
  • 5
  • 40
  • 67
4
votes
1 answer

Using QString causes crash after QMap::remove

I have the following code: class NamedObjectContainer { //... QMap mUsed; //... }; const StoredObject* NamedObjectContainer::use(const QString& name, const QString& userId) { qDebug()<
Osmin
  • 426
  • 3
  • 12
3
votes
1 answer

Nested QMap and QList won't let me append/push_back

I am trying to utilize a nested QList: QMap > > teamGames; for (int team1 = 1; team1 <= TOTAL_TEAMS; ++team1) { QMap> games; teamGames[team1]=games; QList home; QList away; …
gollumullog
  • 1,249
  • 2
  • 14
  • 22
3
votes
1 answer

How to rename Key for QMap?

I have this QMap myTable like this (1, {something0}) (3, {something1}) (5, {something2}) (8, {something3}) How can I change Key for myTable with first key begin from 0? (0, {something0}) (1, {something1}) (2, {something2}) (3,…
songvan
  • 369
  • 5
  • 21
3
votes
1 answer

Qt: Find closest QVector3D in QMap

i have a QMap like this: "1" (0.183,-0.232,0.747) "2" (1.232, 1.322,-0.123) etc. I need a function which input is a QVector3D and which output is the closest key to the input vector. For Example: InputVector(0.189,-0.234,0.755) -> Output: "1" Any…
Michael
  • 43
  • 3
3
votes
0 answers

Set map extent to min and max lat/long using qmap

I have point data for a number of individuals and generate maps for each individual using a for loop. Some individuals travel much further than others on a daily basis so the extent/zoom for each individual needs to be different. Within a loop I…
B. Davis
  • 3,391
  • 5
  • 42
  • 78
3
votes
1 answer

Application stops responding when using QMap to store objects

A friend of mine and I are trying to make a game in C++ using Qt. We want to store a few QGraphicsTextItem in a QMap to access them during runtime. I've pasted the relevant parts of our code here, and our problem is that the program stops…
Dromnes
  • 302
  • 2
  • 3
  • 12
1
2
3
12 13