qmap

Qt容器类汇总说明

断了今生、忘了曾经 提交于 2019-12-26 00:27:06
版权声明:若无来源注明, Techie亮博客 文章均为原创。 转载请以链接形式标明本文标题和地址: 本文标题:Qt容器类汇总说明 本文地址: http://techieliang.com/2017/12/542/ 文章目录 1. 介绍 2. 本博客的Qt容器使用说明 3. 容器类 4. 迭代器类   4.1. Java风格迭代器   4.2. STL风格迭代器 5. Qt提供的其他容器 6. Qt容器算法复杂性 下述说明来源于 官方文档 1. 介绍 Qt库提供了一组通用的基于模板的容器类。这些类可用于存储指定类型的项。例如,如果你需要一个可调整大小的数组qstrings,使用QVector <QString>。 这些容器类的设计要比STL容器更轻、更安全、更容易使用。如果您不熟悉STL,或者更喜欢做“qt方式”,您可以使用这些类而不是STL类。 Qt还提供了一个foreach关键字,让它来遍历所有的物品存放在一个容器很容易。 qt提供的foreach在c++标准中并没有,在c++11中提供了类似于for(auto t:container)方式遍历容器,此方式qt也支持,个人感觉使用for更好 ……更多介绍看官网 2. 本博客的Qt容器使用说明 QMap 、 QMultiMap 、(当前内容截止此随笔发布日,后续内容请见博客后续更新 本文地址: http://techieliang

QHash storing large amount of data

爷,独闯天下 提交于 2019-12-24 00:45:58
问题 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 GB for both QHash and QMap, why this occurs and how can I optimize it for both speed and memory?(through any other data structure or some tricks to qmap and qhash) 回答1: You've said in the comment that you are using another four ints as key - these

Unicode characters in qt app dont show up

我的梦境 提交于 2019-12-23 11:01:27
问题 I'm trying to display different language strings in my qt app by inserting each language into a QMap<QString, QString> 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 like so in the CTOR: m_langMap.insert(QString::fromWCharArray(L"English"), "english"); m_langMap.insert(QString::fromWCharArray(L"Dansk"), "dansk"); m_langMap.insert(QString::fromWCharArray(L"Nederlands"), "dutch"); m_langMap.insert(QString:

Unicode characters in qt app dont show up

眉间皱痕 提交于 2019-12-23 11:00:14
问题 I'm trying to display different language strings in my qt app by inserting each language into a QMap<QString, QString> 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 like so in the CTOR: m_langMap.insert(QString::fromWCharArray(L"English"), "english"); m_langMap.insert(QString::fromWCharArray(L"Dansk"), "dansk"); m_langMap.insert(QString::fromWCharArray(L"Nederlands"), "dutch"); m_langMap.insert(QString:

Does QMap support custom comparator functions?

£可爱£侵袭症+ 提交于 2019-12-23 07:47:26
问题 I couldn't find a way to set a custom comparator function for QMap , like I can for std::map (the typename _Compare = std::less<_Key> part of its template arguments). Does QMap have a way to set one? 回答1: It's not documented (and it's a mistake, I think), but in you can specialize the qMapLessThanKey template function for your types (cf. the source). That will allow your type to use some other function rather than operator< : template<> bool qMapLessThanKey<int>(const int &key1, const int

QMap iteration crash

自闭症网瘾萝莉.ら 提交于 2019-12-23 03:03:44
问题 I am using Qt 5.5 on Windows 8.1. When I run the code below, the application is able to get through one iteration, but crashes on the second one. 100% reproducible. (Copy/paste it into a Qt Creator instance and test; it might work for you). #include <QCoreApplication> #include <QDebug> #include <utility> using std::pair; int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QMap<QString, pair<QString, QString> > table_def = { {"alpha", {"INTEGER", "PRIMARY KEY"}}, {"beta", {

How do you serialize a QMap?

人盡茶涼 提交于 2019-12-22 13:08:08
问题 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

Insert function pointer into QMap (Qt)

无人久伴 提交于 2019-12-12 22:36:52
问题 I am creating sort of a router for REST API in Qt and I am facing problem with inserting the function pointer into the QMap. I have class IModule from which the other modules are derivated. Important lines of IModule.h are typedef QByteArray* (*IBusAction)(IBus * , ProxyRequest *); class IModule : public QObject { Q_OBJECT protected: QMap<QString , IBusAction > *m_actions; Then I have UserModule which is derived from IModule and in .cpp file I have these lines: QByteArray* UserModule::create

Invalidate pointer values inside a QMap

 ̄綄美尐妖づ 提交于 2019-12-11 23:17:37
问题 I'm having what seems to be a weird issue, but it could be a quirk of how QMap's work and I just don't understand it. It's tough to summarize the problem, but I'll do my best. I have a class A , with a QMap<QString, someType*> mySomeTypeMap; . When I load a new file in my program, I want to delete all the contents of this QMap so I can repopulate it with new data. I do that by doing the following: foreach (QString key, mySomeTypeMap.keys()) { someType* toDelete = mySomeTypeMap.take(key); /

Size of Qt containers: is QMap much larger than Qlist?

↘锁芯ラ 提交于 2019-12-11 19:19:53
问题 I am developing a software which maps information in 3D space. I use a container to hold this information. The container which I use is QList< QList< QMap<float, QList<quint16> > > > lidardata; which basically is a 2D grid representing a rectangular area where each cell is 1 meter x 1 meter, and in each cell the QMap contains a key value representing height and a list of four related values at that height. This way I can store five values (height + other values). I insert values in a loop