Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Cannot save the contents of a QGraphicsScene in QGraphicsView

Cannot save the contents of a QGraphicsScene in QGraphicsView

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 855 Views
  • 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 Offline
    P Offline
    piyushraut22
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      1
      • SGaistS SGaist

        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.

        P Offline
        P Offline
        piyushraut22
        wrote on last edited by
        #3

        @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
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          0

          • Login

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