QVariant::save/load: unable to save type X
-
Hi, i use QListWidget in my gui. List widget items has data with type QObject* that points to my custom QObject derived class. When I drag and drop items, program outputs these lines:
QVariant::save: unable to save type 136.
QVariant::load: unable to load type 136.
The program has unexpectedly finished.
and crash. What would be the problem? -
I think i solved the problem. First, i look pointer classes like QPointer, QSharedDataPointer etc for stream operators that needed by qRegisterMetaTypeStreamOperators. I haven't found any. Then i set data as qint32. It works fine but storing pointers with qint32 type seems little weird.
-
"bug report":http://bugreports.qt.nokia.com/browse/QTBUG-15265
I added sample code at comment. You can try quickly.
-
I used debugger and didn't get any useful information. My project that produces this bug: "project":http://rapidshare.com/files/430390643/qlistwidgetitem_test.zip
-
Instead of
@
item->setData( Qt::UserRole, QVariant::fromValue( ( QObject* ) new Foo() ) );
@set your data this way:
@
item->setData( Qt::UserRole, QVariant::fromValue( reinterpret_cast<quintptr>(new Foo()) ) );
@See the API Docs for a detailed description of "quintptr":http://doc.qt.nokia.com/4.7/qtglobal.html#quintptr-typedef when you get the value back from the item you must cast it back to the original pointer type with
@
reinterpret_cast<Foo *>(value);
@ -
You can find some nice infos on "cplusplus.com":http://www.cplusplus.com/doc/tutorial/typecasting/, also the example is taken from somewhere of the Qt sources, to be honest :-)
-
C Christian Ehrlicher referenced this topic on