Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QVariant::save/load: unable to save type X
Qt 6.12 LTS is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved General and Desktop
19 Posts 3 Posters 31.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    t3chNo
    wrote on last edited by
    #3

    A graphicsitem that inherits from QObject and QGraphicsPixmapItem.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexander
      wrote on last edited by
      #4

      you must register your data: @qRegisterMetaType(), qRegisterMetaTypeStreamOperators()@

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alexander
        wrote on last edited by
        #5

        are you insert graphicsitem as pointer?

        1 Reply Last reply
        0
        • T Offline
          T Offline
          t3chNo
          wrote on last edited by
          #6

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

          1 Reply Last reply
          0
          • T Offline
            T Offline
            t3chNo
            wrote on last edited by
            #7

            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.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              t3chNo
              wrote on last edited by
              #8

              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?

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #9

                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 :-)

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  t3chNo
                  wrote on last edited by
                  #10

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

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #11

                    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.

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      t3chNo
                      wrote on last edited by
                      #12

                      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.

                      1 Reply Last reply
                      0
                      • ? Offline
                        ? Offline
                        A Former User
                        wrote on last edited by
                        #13

                        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.

                        1 Reply Last reply
                        0
                        • T Offline
                          T Offline
                          t3chNo
                          wrote on last edited by
                          #14

                          "bug report":http://bugreports.qt.nokia.com/browse/QTBUG-15265

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

                          1 Reply Last reply
                          0
                          • ? Offline
                            ? Offline
                            A Former User
                            wrote on last edited by
                            #15

                            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?

                            1 Reply Last reply
                            0
                            • T Offline
                              T Offline
                              t3chNo
                              wrote on last edited by
                              #16

                              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

                              1 Reply Last reply
                              0
                              • ? Offline
                                ? Offline
                                A Former User
                                wrote on last edited by
                                #17

                                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);
                                @

                                1 Reply Last reply
                                0
                                • T Offline
                                  T Offline
                                  t3chNo
                                  wrote on last edited by
                                  #18

                                  Sorry for late answer, notification mail didn't come or i didn't see it. Thanks for quintptr, it is more appropriate than qint64. I couldn't find documentation for reinterpret_cast btw. Could you send me link if you know where it is?

                                  1 Reply Last reply
                                  0
                                  • ? Offline
                                    ? Offline
                                    A Former User
                                    wrote on last edited by
                                    #19

                                    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 :-)

                                    1 Reply Last reply
                                    0
                                    • Christian EhrlicherC Christian Ehrlicher referenced this topic on

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt
                                    • Unsolved