qvector

No matching call to default constructor, when using QVector

不想你离开。 提交于 2019-11-28 12:54:54
I have a class B that creates an object of a class A and calls a method of the object. a.h #ifndef A_H #define A_H class A { public: A(int); void function(); }; #endif // A_H a.cpp #include "a.h" A::A(int x) { } void A::function(){ //Do something. } b.h #ifndef B_H #define B_H #include <QVector> #include <a.h> class B { public: B(int); QVector<A> list; }; #endif // B_H b.cpp #include "b.h" B::B(int y) { list.append(A(y)); list[0].function(); } The problem is that this does not compile. It returns "no matching function to call 'A:A()'". I know that this can be solved with a forward declaration

Why QVector::size returns int?

六眼飞鱼酱① 提交于 2019-11-28 10:46:44
std::vector::size() returns a size_type which is unsigned and usually the same as size_t , e.g. it is 8 bytes on 64bit platforms. In constrast, QVector::size() returns an int which is usually 4 bytes even on 64bit platforms, and at that it is signed, which means it can only go half way to 2^32. Why is that? This seems quite illogical and also technically limiting, and while it is nor very likely that you may ever need more than 2^32 number of elements, the usage of signed int cuts that range in half for no apparent good reason. Perhaps to avoid compiler warnings for people too lazy to declare

What is the reason of QVector's requirement for default constructor?

情到浓时终转凉″ 提交于 2019-11-28 03:46:39
问题 I can see that that classes are treated as complex objects which are required for calling default constructor: void QVector<T>::defaultConstruct(T *from, T *to) { if (QTypeInfo<T>::isComplex) { while (from != to) { new (from++) T(); } ... } But it's not clear why is it needed to construct objects in the 'hidden' area of QVector. I mean these objects are not accessible at all, so why not just to reserve the memory instead of the real object creation? And as a bonus question, I would like to

Why do Qt's container classes not allow movable, non-copyable element types?

我们两清 提交于 2019-11-27 07:45:10
问题 The Qt container classes QList<T> , QVector<T> etc. require their element types to be copyable. Since C++11, the STL containers require their element type to be copyable or movable only. Why do the Qt containers not support move-only element types? 回答1: Qt bug #54685 has explicit confirmation from Qt developers that move-only types are not (and will never be) supported because of Qt containers' principle of implicit sharing. When you copy one Qt container to another, you're not doing a deep

No matching call to default constructor, when using QVector

拈花ヽ惹草 提交于 2019-11-27 07:14:51
问题 I have a class B that creates an object of a class A and calls a method of the object. a.h #ifndef A_H #define A_H class A { public: A(int); void function(); }; #endif // A_H a.cpp #include "a.h" A::A(int x) { } void A::function(){ //Do something. } b.h #ifndef B_H #define B_H #include <QVector> #include <a.h> class B { public: B(int); QVector<A> list; }; #endif // B_H b.cpp #include "b.h" B::B(int y) { list.append(A(y)); list[0].function(); } The problem is that this does not compile. It

Why QVector::size returns int?

被刻印的时光 ゝ 提交于 2019-11-26 21:09:00
问题 std::vector::size() returns a size_type which is unsigned and usually the same as size_t , e.g. it is 8 bytes on 64bit platforms. In constrast, QVector::size() returns an int which is usually 4 bytes even on 64bit platforms, and at that it is signed, which means it can only go half way to 2^32. Why is that? This seems quite illogical and also technically limiting, and while it is nor very likely that you may ever need more than 2^32 number of elements, the usage of signed int cuts that range