qlist

Constant class members, assignment operator and QList

◇◆丶佛笑我妖孽 提交于 2019-12-04 07:38:57
Please conform if I am correct and tell me whether there is a better solution: I understand that objects with constant members like int const width; can not be handled by the synthetic assignment operator that is implicitly created by the compiler. But QList (and I suppose std::list, too) needs a working assignment operator. So when I want to use objects with constant members and QList I have three possibilities: Don't use constant members. (Not a solution) Implement my own assignment operator. Use some other container that does not need assignment operators Is that correct? Are there other

When does a deep copy happen to a QList?

徘徊边缘 提交于 2019-12-04 00:38:22
问题 In a class I'm working on, I am juggling several QList s. I have heard that Qt tries not to make deep copies of lists whenever possible. From what I understand, that means that no deep copy happens when you do this: QList<int> myList; myList << 1 << 2 << 3 << 4; QList<int> otherList = myList; // No deep copy In some cases, I need to make sure a deep copy never happens to the QList . Exactly what kind of operation or action do I need to make sure to avoid in order to make sure a deep copy

Qt - QList const correctness

匿名 (未验证) 提交于 2019-12-03 08:44:33
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: A QList<T *> can't easily be const-correct. Consider the function void f ( QList < T *> list ) { list [ 0 ]-> constFunction (); } I can change f to void f ( QList < const T *> list ) but then I can't do f ( QList < T *>()); //Compile error anymore, since the compiler can't implicitely cast QList<T *> to QList<const T *> . However, I can explicitely reinterpret-cast the QList as follows: template < typename T > inline QList < const T *> & constList ( const QList < T *> & list ) { return ( QList < const T *> &) list ; } This enables

QList and delete

若如初见. 提交于 2019-12-03 06:02:39
I have a QList with pointers to objects with class type Model . I would like to delete appropriately this QList after it has being used. I know Qt philosophy is to avoid C-style memory management. How do I delete this QList ? You could use qDeleteAll : qDeleteAll(lstMdls); lstMdls.clear(); Unihedron As seen from an earlier revision , this was OP's approach: QList<Model*>lstMdls; get Data(lstMdls); /* * Do other things */ for(int i=0;i<lstMlds.size();i++) { delete lstMdls.at(i); } 来源: https://stackoverflow.com/questions/11555630/qlist-and-delete

Qt容器类之二:迭代器

匿名 (未验证) 提交于 2019-12-02 23:43:01
遍历一个容器可以使用迭代器(iterators)来完成,迭代器提供了一个统一的方法来访问容器中的项目。Qt的容器类提供了两种类型的迭代器:Java风格迭代器和STL风格迭代器。 如果只是想按顺序遍历一个容器中的项目,那么还可以使用Qt的foreach关键字。 Java风格的迭代器在Qt4中加入,比STL风格的迭代器更易于使用,但是以轻微的效率作为代价, 它们的API以Java的迭代器类为模型。 对于每个容器类,都有两种Java风格的迭代器类型:一种是只读,另一种是可读写。 容器 只读迭代器 可读写迭代器 QList<T>, QQueue<T> QListIterator<T> QMutableListIterator<T> QLinkedList<T> QLinkedListIterator<T> QMutableLinkedListIterator<T> QVector<T>, QStack<T> QVectorIterator<T> QMutableVectorIterator<T> QSet<T> QSetIterator<T> QMutableSetIterator<T> QMap<Key, T>, QMultiMap<Key, T> QMapIterator<Key, T> QMutableMapIterator<Key, T> QHash<Key, T>,

QT: QList模板类接口函数

匿名 (未验证) 提交于 2019-12-02 23:34:01
插入操作:insert() 函数原型: void QList::insert(int i, const T &value) 在索引后插入值 i:索引 value:插入值 Example: QList<QString> list; list << "alpha" << "beta" << "delta"; list.insert(2, "gamma"); // list: ["alpha", "beta", "gamma", "delta"] 替换操作:replace() 函数原型: void QList::replace(int i, const T &value) 替换索引处的值 i:索引 value:替换值 Example: QList<QString> list; list << "alpha" << "beta" << "delta"; list.replace(2, "aaa"); // list: ["alpha", "beta", "aaa"] 移除操作:removeAt() 函数原型: void QList::removeAt(int i) 移除索引位置处的值 i:索引 移动操作:move() 函数原型: void QList::move(int from, int to) 从哪个索引位置移动到哪个索引位置 Example: QList<QString> list;

Qt 5.5 project build error in Qt 5.8

落爺英雄遲暮 提交于 2019-12-02 07:33:42
I was developing a simple application on Qt 5.5. Since Qt 5.5 does not have QChart class features, I had to install and build my Qt 5.5 project on the 5.8 distribution. For my project I am using this 3rd party software called the QXlsx to create and edit Excel spreadsheets. This library was working flawlessly in Qt 5.5 but fails to compile on the Qt 5.8 version. The compilation returns the following error; /Users/Vino/Documents/My Stuff/Qt Projects/Fundemental Analysis/FundementalAnalysis/3rdparty/qtxlsx/src/xlsx/xlsxzipreader.cpp:52: error: implicit instantiation of undefined template

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

笑着哭i 提交于 2019-12-02 04:31:34
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(); private: QString _rightsPath; // PATH to the file containing rights }; I've implemented these classes,

Qt 多线程信号和槽——自定义参数传递

戏子无情 提交于 2019-12-01 12:39:56
需求:想要使用信号传递double数组 定义信号: void signal_double(QList<double>); 编译&运行: Object::connection: Cannot queue arguments of type 'QList<double>' (Make sure 'QList<double>' is registered using qRegisterMetaType().)) 原因:   自定义的数据类型作为信号槽参数传递的时候,需要使用 qRegisterMetaType() 函数对该参数进行注册 解决: 1、添加头文件 # include <QMetaType> 2、注册 qRegisterMetaType<QList<double> > ( "QList<double>"); 3、注意:在哪儿连接信号和槽,在哪儿注册。 参考:http://blog.csdn.net/kusey/article/details/7995815 来源: https://www.cnblogs.com/shuoguoleilei/p/11686298.html

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

百般思念 提交于 2019-12-01 08:07:52
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 objects at the same time? The objects in the list are thread safe and cant be read/write by different