Unsolved Hot to convert (cast) QHash<int, StructOfQByteArray1AndQbyteArray2> to QHash<int, QByteArray1> with minimum resource cost?
-
ok. let's find out how well do you know C++.
ok we havestruct StructOfQByteArray1AndQbyteArray2 { QByteArray array1; QByteArray array2; }
Hot to convert (cast)
QHash<int, StructOfQByteArray1AndQbyteArray2>
toQHash<int, QByteArray1>
with minimum resource cost?where I want to use this?
when working withQAbstractItemModel
I implement methodQHash<int, QByteArray> QAbstractItemModel::roleNames() const
but in app I have more complexQHash<int, StructOfQByteArray1AndQbyteArray2>
with some extra data. -
well if u want to avoid copy bytearray
maybe use something like
QHash<int, QByteArray1 *>
and set to point to the real QByteArray1; ? -
@mrjj but I have to return exactly data, not pointer
QHash<int, QByteArray> QAbstractItemModel::roleNames() const
-
@Kofr said:
ahh its something you must return.
Well i think u need copy then since i doubt there is way to cast the original
StructOfQByteArray1AndQbyteArray2 -
Hi,
From a C++ POV: you can't do such a cast.
What resources do you want to optimize ? Speed ? Memory use ?
-
@SGaist Speed. So you want to say that it is ok to manually fill in
QHash<int, QByteArray>
before returning and just allow data to be copied as rvalue? -
I'm just saying that you can't cast (as in static_cast, dynamic_cast etc.) such a hash of int and struct to a hash of int and QByteArray.
Are your role names going to be dynamically created ? Changed ?
-
@SGaist yes, I will have custom roles for some delegates.
-
Ok but these roles are already known, no ?