November 11, 2010

t3chNo t3chNo
Lab Rat
55 posts

QVariant::save/load: unable to save type X

Page  
1

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?

18 replies

November 11, 2010

Alexander Kuchumov Alexander Kuchumov
Lab Rat
377 posts

Can you describe data, which you insert in QListWidgetItem as QVariant?

November 11, 2010

t3chNo t3chNo
Lab Rat
55 posts

A graphicsitem that inherits from QObject and QGraphicsPixmapItem.

November 11, 2010

Alexander Kuchumov Alexander Kuchumov
Lab Rat
377 posts

you must register your data:

  1. qRegisterMetaType(), qRegisterMetaTypeStreamOperators()

November 11, 2010

Alexander Kuchumov Alexander Kuchumov
Lab Rat
377 posts

are you insert graphicsitem as pointer?

November 11, 2010

t3chNo t3chNo
Lab Rat
55 posts

Yes, as pointer. I cast QObject* when i set data.

November 11, 2010

t3chNo t3chNo
Lab Rat
55 posts

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.

November 11, 2010

t3chNo t3chNo
Lab Rat
55 posts

Btw, item that has data with unregistered type and QAstractItemView::defaultDropAction set to IgnoreAction or CopyAction or LinkAction causes segmentation fault. Is this a desired behaviour?

November 11, 2010

Volker Volker
Ant Farmer
5428 posts

If you just copy around pointers it might be that the original object has been deleted already and you work on a dangling pointer then.

A segmentation fault is never a desired behavior :-)

November 11, 2010

t3chNo t3chNo
Lab Rat
55 posts

I think it is not desired too. Object is not deleted btw. I’ll report this issue.

November 11, 2010

Volker Volker
Ant Farmer
5428 posts

Are you sure, it is not deleted? Did you consider using a debugger to look where the segfault pops up? You’ll get a nice stack trace that leads you to the misbehaving line of code.

November 12, 2010

t3chNo t3chNo
Lab Rat
55 posts

Yes i am sure object is not deleted. Object’s pointer is not important. QListWidget doesn’t try to access my custom object. It just stores my object’s memory address. I made data type to qint64 btw. qint32 is not enough.

November 12, 2010

Volker Volker
Ant Farmer
5428 posts

You should use a debugger to see where the segfault happens (access to which object in which place, etc.) We can’t help any further on that. It’s unlikely to be a bug in the Qt libs as thousands of programmers use this code without any problems.

November 12, 2010

t3chNo t3chNo
Lab Rat
55 posts

bug report [bugreports.qt.nokia.com]

I added sample code at comment. You can try quickly.

November 12, 2010

Volker Volker
Ant Farmer
5428 posts

Nobody can produce an executable from this snippet.

You should create a minimal, complete project to demonstrate the problem.

And could you please tell us if you used a debugger to look where and on which object the segfault happened?

November 12, 2010

t3chNo t3chNo
Lab Rat
55 posts

I used debugger and didn’t get any useful information. My project that produces this bug: project [rapidshare.com]

Page  
1

  ‹‹ [Solved] QSpinBox: how to signal only when editing finished?      [Solved] Image in a tooltip ››

You must log in to post a reply. Not a member yet? Register here!