I`m trying to use a QVector with a custom object named RoutineItem.
But this error is given:
C:\Qt\5.2.1\mingw48_32\include\QtCore\qvector.h:265: error: no matching function for call to 'RoutineItem::RoutineItem()'
This is the RoutineItem constructor:
RoutineItem(QString Name,int Position,int Time,bool hasCountdown = false,bool fastNext = false);
If I remove all the constructor arguments I no longer get that error. How can I use QVector with a custom object that has arguments?
The problem is that QVector requires that the element has a default constructor (that is the error message about). You can define one in your class. For example:
class RoutineItem {
RoutineItem(QString Name, int Position,
int Time, bool hasCountdown = false,
bool fastNext = false);
RoutineItem();
[..]
};
Alternatively, you can let all arguments have a default values:
class RoutineItem {
RoutineItem(QString Name = QString(), int Position = 0,
int Time = 0, bool hasCountdown = false,
bool fastNext = false);
[..]
};
Alternatively, you can construct a default value of RoutineItem and initialize all vector items by it:
RoutineItem item("Item", 0, 0);
// Create a vector of 10 elements and initialize them with `item` value
QVector<RoutineItem> vector(10, item);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With