Hi,
I have a standard C++ object.
class A
{
// ...
};
class A
{
// ...
};
To copy to clipboard, switch view to plain text mode
I can't (and I don't want to) define it as a Qt type.
Though, I still like to put it in the model (QStandardItemModel for instance).
So far, I was able to but a raw pointer into the model with the very ugly following code :
// I have
const A &a = ; //...
// Writing
item->setData(
qVariantFromValue(
reinterpret_cast<void*>(
const_cast<A*>(
&a
)
)
),
Role
);
// Reading
const A &a = *reinterpret_cast<A*>(
const_cast<const void*>(
item->data(Role).value<void*>()
)
);
// I have
const A &a = ; //...
// Writing
item->setData(
qVariantFromValue(
reinterpret_cast<void*>(
const_cast<A*>(
&a
)
)
),
Role
);
// Reading
const A &a = *reinterpret_cast<A*>(
const_cast<const void*>(
item->data(Role).value<void*>()
)
);
To copy to clipboard, switch view to plain text mode
How bad is this ?
Anything better ?
Thanks !
PS0 : I read the method with Q_DECLARE_METATYPE.
PS1 : I could always create an intermediate Qt type which would embed my non Qt type...but that seems heavy too.
Bookmarks