I've got the following struct :
struct HidItem
{
HidItem(){}
HidItem(QString commandName, uint commandValue)
{
name = commandName;
value = commandValue;
}
QString name;
uint value;
};
and trying to create an instance like so:
HidCommandModel::HidCommandModel()
: QAbstractListModel(),
hidData(new QVector<HidItem>(10))
{
HidItem *hidItem = new HidItem("USAGE_PAGE", 1);
hidData->append(*(hidItem));
}
This isn't working too well, as only the uint commandValue gets assigned to the HidItem instance, and not the QString "USAGE_PAGE"
I haven't coded C++ in quite a few years, but this seems to me that I'm passing the string incorrectly, and needs to have some kung fu involved with pass by reference, pointers and copy and write.
The theory is there, but my practical skills are letting me down horribly today. Can anyone assist?
new, copying it, and then discarding the pointer. TryhidData->append(HidItem("USAGE_PAGE, 1))instead.hidDatashould probably be aQVectorobject, not a pointer. It's best to avoidnewunless you really need it.