qlist

Save and load QList<Class*> to file

帅比萌擦擦* 提交于 2020-01-03 05:36:42
问题 I have a class ContactData and a class FriendList holding a QList and I overloaded the << / >> operators. contactdata.h class ContactData { //all public for testing public: ContactData(); QString m_name; QString m_description; bool m_online; }; QDataStream &operator<<(QDataStream& out, ContactData& contactData); QDataStream &operator>>(QDataStream& in, ContactData* contactData); contactdata.cpp QDataStream &operator<<(QDataStream &out, ContactData& contactData) { out << contactData.m_name;

error: type/value mismatch at argument 1 in template parameter list for 'template<class T> class QList'

こ雲淡風輕ζ 提交于 2019-12-31 03:43:05
问题 I'm trying to have a QList and getting the error when compiling! Here's my code: class Right { public: Right(); Right(const Right& other); Right(RightName name, QDate validity_date); bool isValid() const; bool operator==(const Right& other)const; Right &operator=(const Right &other); QString name; QDate expiryDate; }; And then using this Right in a QList class FileRightsRepo { public: FileRightsRepo(QString rightsPath); ~FileRightsRepo() { } // IRightsRepo interface QList<Right> getRights();

Can two threads read from the same QList at the same time?

帅比萌擦擦* 提交于 2019-12-30 10:26:09
问题 Pretty new to threading and I have this QList that the threads share between them. They all have their own space that they can work on, and the GUI (the model/view) access this list constantly. I then get this crash which points to QDataList.size(). The debugging doesn't really help me since I never come across this issue if I step through the code and when I'm trying to what qList that's crashing, there's no info available. So, my question is: Is it possible to get the Qlists size and read

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

List of iterators to collect entries from various lists

≯℡__Kan透↙ 提交于 2019-12-25 08:43:35
问题 A class TaskGroup mainly contains a list of Task s. I want to collect certain tasks ta1 , ta2 , tb3 , ... from various groups ga , gb , gc , ... and use this list in a display window/class. The choice of tasks for the collection is of no concern for this question. (As the question is rather conceptual than technical, the examples are mostly pseudo code. Since I'm using Qt in this particular case, I'll be using Qt classes, but the question shouldn't be limited to this case.) class Task; class

斗地主中跟牌逻辑分析

放肆的年华 提交于 2019-12-23 17:28:22
QList<card> Method::PlayBeatHand(Hand hand) { // 先固定住最优顺子,从余下牌中打出 QList<card> left = m_cards; //查找最优顺子并且从当前牌中移除 QList<QList<card> > cardlll=Method(m_player,left).PickOptimalSeqSingles(); for(int i=0;i<cardlll.size();i++) for(int j=0;j<cardlll[i].size();j++ ) left.removeOne(cardlll[i][j]); //left.Remove(Method(m_player, left).PickOptimalSeqSingles()); //压单牌 if (hand.getHandType() == Hand_Single) // 如果压单牌,尽量从单张牌中挑 { QList<QList<card> > singleArray = Method(m_player, left).FindCardsByCount(1); for (int i = 0; i < singleArray.size(); i++) { if (Hand(singleArray[i]).Defeat(hand)) { return

Use QQmlListProperty to show and modify QList in Qml

寵の児 提交于 2019-12-19 08:13:23
问题 again, well i have a question (and maybe a problem), i make a program with qt and qml in qt5 and qml with qtquick 2.0, and i have a c++ model qlist, and i need modify the list in runtime, i use q QQmlListProperty and show the items in qml, but they are not hide and show in the moment when i add or remove my code is next: class ConceptsList: public QObject{ Q_OBJECT Q_PROPERTY(QQmlListProperty<Concept> concepts READ concepts NOTIFY conceptsChanged) Q_CLASSINFO("DefaultProperty", "concepts")

Use QQmlListProperty to show and modify QList in Qml

跟風遠走 提交于 2019-12-19 08:13:00
问题 again, well i have a question (and maybe a problem), i make a program with qt and qml in qt5 and qml with qtquick 2.0, and i have a c++ model qlist, and i need modify the list in runtime, i use q QQmlListProperty and show the items in qml, but they are not hide and show in the moment when i add or remove my code is next: class ConceptsList: public QObject{ Q_OBJECT Q_PROPERTY(QQmlListProperty<Concept> concepts READ concepts NOTIFY conceptsChanged) Q_CLASSINFO("DefaultProperty", "concepts")

Qt: is removing QList elements while iterating using foreach macro possible?

你说的曾经没有我的故事 提交于 2019-12-18 12:45:12
问题 I'm new to Qt and trying to learn the idioms. The foreach documentation says: Qt automatically takes a copy of the container when it enters a foreach loop. If you modify the container as you are iterating, that won't affect the loop. But it doesn't say how to remove an element while iterating with foreach . My best guess is something like: int idx = 0; foreach (const Foo &foo, fooList) { if (bad(foo)) { fooList.removeAt(idx); } ++idx; } Seems ugly to have to scope idx outside the loop (and to

Save QList<int> to QSettings

你说的曾经没有我的故事 提交于 2019-12-17 23:42:50
问题 I want to save a QList<int> to my QSettings without looping through it. I know that I could use writeArray() and a loop to save all items or to write the QList to a QByteArray and save this but then it is not human readable in my INI file.. Currently I am using the following to transform my QList<int> to QList<QVariant> : QList<QVariant> variantList; //Temp is the QList<int> for (int i = 0; i < temp.size(); i++) variantList.append(temp.at(i)); And to save this QList<Variant> to my Settings I