qmap

Map - finding nearest value?

江枫思渺然 提交于 2019-12-11 07:13:58
问题 I am trying find nearest RGB value in QMap (I know it probably should be HSV, but that is not the problem). Here is what I got so far: it = images_map.find(current_rgb); if(it != images_map.begin()){ mi = images_map.lowerBound(current_rgb).value(); } else{ mi = images_map.upperBound(current_rgb).value(); } My map looks like this has that indexes: images_map[ 4283914078 ] images_map[ 4284046165 ] images_map[ 4284902241 ] images_map[ 4289239953 ] images_map[ 4282200377 ] images_map[ 4289440688

QMap but without sorting by key

拜拜、爱过 提交于 2019-12-10 20:32:57
问题 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? 回答1: QMap is implemented as a tree, which means that the insertion order does not matter. It appears that you are looking for a queue . However, if you need a container which can be iterated in both insertion order and at the same time accessed through a specific key, then Qt has no

Order of items in QMap and QMultiMap

佐手、 提交于 2019-12-10 17:26:27
问题 I would like to use QMultiMap (which is derived from QMap ) to store key/value pairs. Since I can have keys multiple times I would prefer to use QMultiMap . Assume I would insert the following pairs in the given order: "C" -> 5 "A" -> 10 "B" -> 77 "B" -> 1 "X" -> 314159 When iterating over the map (using java style iterators preferably) I need the order of equal-key-pairs to be preserved. I.e. "B" -> 77 and "B" -> 1 should appear exactly in insertion order when iterating. The order between

QMap::remove操作,并不会调用值的析构,跟QTreeWidget同类,需要主动去释放

↘锁芯ラ 提交于 2019-12-10 15:28:18
void test_MapRemvoe() { DBOperator * painter = new DBOperator; QMap<int , DBOperator*> map; map.insert(1, painter); DBOperator * painterOther = map.value(1); qDebug()<<painterOther; map.remove(1); qDebug()<<painterOther; } 15:08:56: Starting E:\Qt_projcet\play\build-play-Desktop_Qt_5_12_2_MinGW_64_bit-Debug\debug\play.exe... 15:10:09: Debugging starts DBOperator(0x1447800) //remove前后地址是一样的 DBOperator(0x1447800) //remove前后地址是一样的 15:10:41: Debugging has finished 来源: https://www.cnblogs.com/azbane/p/12016836.html

Can't pass QMap through to SLOT

心不动则不痛 提交于 2019-12-10 10:42:47
问题 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, SIGNAL(clicked()), signalMapper, SLOT(map())); connect(signalMapper, SIGNAL(mapped(QString)), this, SLOT(addMenu(QString))); Now, I am trying to pass a QMap < QString, QString > through to addMenu instead of just a QString, but I get the error: no matching function

How to deep copy QMap and other Qt containers

天大地大妈咪最大 提交于 2019-12-10 03:54:46
问题 Generally speaking, what is the correct way to deep copy Qt containers? I'm not worried about deep copying the containers recursively, although addressing such would be helpful. 回答1: Despite what everyone will tell you - that you don't deep copy Qt containers - there are situations in which you simply need to perform an actual deep copy instead of just a shallow one. To do that, use detach() : container1 = container2; container1.detach(); 来源: https://stackoverflow.com/questions/16800206/how

How do you serialize a QMap?

老子叫甜甜 提交于 2019-12-06 09:31:42
I'm trying to learn how to serialize QMap objects in windowed applications, using this code: #include "mainwindow.h" #include "ui_mainwindow.h" #include <QFile> #include <QString> #include <QDataStream> #include <QMap> #include <QDebug> void write () { QString filename = "Z:/snippets.txt"; QFile myFile (filename); if (!myFile.open(QIODevice::WriteOnly)) { qDebug() << "Could not write " << filename; return; } QMap<QString,QString> map; map.insert("one","this is 1"); map.insert("two","this is 2"); map.insert("three","this is 3"); QDataStream out (&myFile); out.setVersion(QDataStream::Qt_5_3);

Can't pass QMap through to SLOT

空扰寡人 提交于 2019-12-06 06:15:06
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, SIGNAL(clicked()), signalMapper, SLOT(map())); connect(signalMapper, SIGNAL(mapped(QString)), this, SLOT(addMenu(QString))); Now, I am trying to pass a QMap < QString, QString > through to addMenu instead of just a QString, but I get the error: no matching function for call to 'QSignalMapper::setMapping'. Do I need to create a typeDef or something? .h public slots:

How to deep copy QMap and other Qt containers

余生颓废 提交于 2019-12-05 04:35:49
Generally speaking, what is the correct way to deep copy Qt containers? I'm not worried about deep copying the containers recursively, although addressing such would be helpful. Despite what everyone will tell you - that you don't deep copy Qt containers - there are situations in which you simply need to perform an actual deep copy instead of just a shallow one. To do that, use detach() : container1 = container2; container1.detach(); 来源: https://stackoverflow.com/questions/16800206/how-to-deep-copy-qmap-and-other-qt-containers

Get boundaries to come through on states

泪湿孤枕 提交于 2019-12-04 06:43:22
问题 Edit 7 : After quite a bit of help, I've been able to get a map that is getting close to the results I need. But I still need to have the state boundaries come through on the map, but I can't figure it out. In order to make a reproducible example that would be appropriate I need to link to the data set since the dput is so large. To make things easy, I subset only three states, but where the boundary lines do not show up. I would like to be able to have the boundary lines come through the