Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Cannot save the contents of a QGraphicsScene in QGraphicsView

    General and Desktop
    2
    4
    632
    Loading More Posts
    • 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.
    • P
      piyushraut22 last edited by

      I want my application to save the contents of my scene which contains graphics items in it and later be able to retrieve all those items(not as a QPixmap, but as actual individual items).
      I have tried using Qsettings but get a QVariant error.

      QSettings settings("AdvProgLab","ERapp");
      settings.beginGroup("MainWindow");
      settings.setValue("saved_scene",scene);      //Here, scene is a QGraphicsScene
      settings.endGroup();
      

      And the error which I am getting is:

      
      
          qvariant.h:471: error: ‘QVariant::QVariant(void*)’ is private inline QVariant(void *) Q_DECL_EQ_DELETE; ^
      
          error: use of deleted function ‘QVariant::QVariant(void*)’
      
      

      Can anybody please explain me where I am going wrong ?
      Or is there any other way by which I can save the QGraphicsItems and later retrieve them.

      Thank You.

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi and welcome to devnet,

        You are wrong with your assumption. From what you wrote, you are basically trying to save a pointer to a scene in your settings. If you want to store the content of the scene, it's up to you to serialise your items in a reproducible way. i.e. save each item's position and content as well as properties you are interested in and then load them back on start.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        P 1 Reply Last reply Reply Quote 1
        • P
          piyushraut22 @SGaist last edited by

          @SGaist I understood what you said but i have one doubt regarding your reply.
          Suppose i have few QGraphicsRectItem and QgraphicsEllipseItem in my scene, according to you i should save the position and size of each item but while retrieving, how will the scene know whether it was a RectItem or and EllipseItem ?

          I am new to QT so pardon me if i sound silly.
          Thank You.

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            You have to store enough information about your items in order to rebuild them when you load the information back.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • First post
              Last post