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
3
votes
3 answers

Get item at specific offset of QMap

I have a QMap that represents a database row. The items are indexed by column name: QMap mapOfItems_; I then have a method to retrieve item by columnn name: QVariant ImportDataSourceRow::byName( const QString& name ) { …
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
3
votes
3 answers

Is there any way to set a class in the QMap value?

Is there any way to add & use a class in the QMap value? I wanna use QMap map; in Qt. and when I want to set it's value in a function, some errors appear: C:\Qt\Qt5.5.0\5.5\mingw492_32\include\QtCore\qglobal.h:1043: error: 'QWidget&…
s.m
  • 209
  • 2
  • 7
  • 17
3
votes
2 answers

Is it possible to store QColor in a QMap as key

So, I have simple code QMap colors; for(int w = 0; w < image.width(); ++w) for (int h = 0; h < image.height(); ++h) colors[QColor::fromRgb(image.pixel(w,h))]++; The error message is no match for 'operator<' (operand types…
cassandrad
  • 3,412
  • 26
  • 50
3
votes
1 answer

How to use Qmap inside a Qhash?

I have to create a QHash with a map QMap inside it, I have tried to write it as…
CowboY
  • 99
  • 2
  • 7
3
votes
4 answers

QSet in QMap or QHash

I have QMap and I want to make QSet the key of it, I couldn't do that because QSet is not comparable. for example: QSet intSet; QMap, char> charSet; intSet.insert(1); intSet.insert(2); intSet.insert(3); charSet.insert(intSet,…
MhdAljuboori
  • 475
  • 4
  • 15
2
votes
3 answers

Is there a map-like tool in QT that can be iterated over inserted index?

From the Qt documentation about QMap::iterator : Unlike QHash, which stores its items in an arbitrary order, QMap stores its items ordered by key. Items that share the same key (because they were inserted using QMap::insertMulti(), or due to…
euraad
  • 2,467
  • 5
  • 30
  • 51
2
votes
1 answer

std::transform over QMap

I have to transform a QMap. I tried to use std::transform as it works for QList, but it's failed to compile. #include #include #include int main(int argc, char *argv[]) { QCoreApplication…
Vencat
  • 1,272
  • 11
  • 36
2
votes
1 answer

QMap::value return reference to temporary

I would like to return a const reference to a QMap value. From what I can understand, QMap is special in that if you try to access a key that does not exist, it will create a value with the default constructor and return it. But if I still…
Idle
  • 37
  • 2
  • 9
2
votes
1 answer

QHash storing large amount of data

I've 10,000,000 entry of type struct{int, int, int, int}. when I store them using QHash or QMap, it occupies large amount of memory, indeed it must take about 10,000,000 * 4 * 4 (sizeof integer) <= 153 MB but when I load my data it takes about 1.2…
abdolahS
  • 663
  • 12
  • 35
2
votes
2 answers

QT - Fill a QMap with only key, and then add values for each key

I would like to know if is it possible to fill a QMap with only key, and then for each key add value. for example, something like : QMap map; map.insert("key", null (??)); Thanks for your answer
iAmoric
  • 1,787
  • 3
  • 31
  • 64
2
votes
2 answers

Convert QMap to JSON

I have a QMap object and I would like to convert it to JSON. I am confused how I would accomplish this. I read QT documentation saying that I can use QDataStream to convert QMap to JSON, but QDataStream seems to convert files:…
Jon
  • 8,205
  • 25
  • 87
  • 146
2
votes
5 answers

Can't pass QMap through to SLOT

So, this works: .h public slots: void addMenu(QString passedName); signals: void clicked(const QString &text); .cpp signalMapper = new QSignalMapper(this); signalMapper->setMapping(button, QString("passed_value")); connect(button,…
user375566
2
votes
2 answers

Sort QMap

I have data struct QMap how can i sort it by int key? Thank you.
0xAX
  • 20,957
  • 26
  • 117
  • 206
2
votes
2 answers

func(QWidget* const &widget) VS func(QWidget* const widget)

I've noticed a peace of code works even throwing away the ampersand/reference signal. QWidget* widget; func(widget); Do the following expressions mean the same? func(QWidget* const &widget) func(QWidget* const widget) I understand both are…
KcFnMi
  • 5,516
  • 10
  • 62
  • 136
2
votes
1 answer

Obtaining position (int) of a QMap::iterator

I have written a QListModel based model to access data stored in a QMap. QMap is guaranteed to be sorted. So a conversion from QMap::iterator or const_iterator to int should be possible and sane. At the moment I decrement the iterator and increment…
Simon Schmeißer
  • 324
  • 4
  • 12
1 2
3
12 13