Details
-
Bug
-
Resolution: Fixed
-
P1: Critical
-
6.5
-
None
-
-
a8792feaa (dev), 08d1a474c (6.5), 3af876d53 (6.6)
Description
Playing with QVariant in ActiveQt, I found that QVariant::canConvert returns true when converting from a Type* to a Type even if the type is not copy-constructible. In such cases, attempting to call QVariant::convert crashes (access violation). To provoke the crash, the target type's QMetaType needs to have an associated meta object.
As I see it, there are two issues
- QVariant::canConvert returns true for non-copyable objects
- QVariant::convert crashes with noncopyable objects (Update: they have to have an associated MetaObject (gadget or QObject))
Reproducer:#include <QtCore> struct MyType : QObject { Q_OBJECT }; int main() { QMetaType valueType{ qRegisterMetaType<MyType>("MyType") }; QMetaType pointerType{ qRegisterMetaType<MyType *>("MyType*") }; MyType instance; MyType *pointer = &instance; QVariant ptrAsVariant{ pointerType, &pointer }; // Why is MyType* considered convertible to MyType? if (ptrAsVariant.canConvert(valueType)) { // The following line crashes and logs 'QVariant: Provided // metatype for 'MyType' does not support destruction and // copy construction' ptrAsVariant.convert(valueType); } } #include "main.moc"
Attachments
Issue Links
- blocks
-
QTBUG-111191 Qutlook Example (ActiveQt) crashes with Qt6.4.2
-
- Closed
-
- relates to
-
QTBUG-115594 Qt Designer + ASAN: global-buffer-overflow
-
- Closed
-