To answer my own question (and help anyone else looking for an (ugly) solution to the same problem):
In the end the problem actually turned out to be - how to modify QVariant string data directly. Turns out the biggest problem was in-place rewriting of QString data. I came up with a solution (though I don't really like it and would prefer something cleaner):
{
void *valuePtr = value.d.is_shared ? value.d.data.shared->ptr : static_cast<void *>(&(value.d.data.c));
QString *text
= reinterpret_cast<QString
*>
(valuePtr
);
QChar* txtPtr
= const_cast<QChar
*>
(text
->constData
());
//yes, const_cast constData(), as data() creates a modifiable copy for (int x = 0; x < text->size(); x++)
}
}
Q_INVOKABLE void wipe(QVariant value)
{
void *valuePtr = value.d.is_shared ? value.d.data.shared->ptr : static_cast<void *>(&(value.d.data.c));
if ((value.type() == QMetaType::QString) && valuePtr) {
QString *text = reinterpret_cast<QString *>(valuePtr);
QChar* txtPtr = const_cast<QChar*>(text->constData()); //yes, const_cast constData(), as data() creates a modifiable copy
for (int x = 0; x < text->size(); x++)
*(txtPtr++) = QChar(0);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks