Results 1 to 17 of 17

Thread: I want to save and retrive a QGraphicsScene

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2008
    Posts
    52
    Qt products
    Qt4
    Thanks
    3

    Default I want to save and retrive a QGraphicsScene

    Hi Friends,
    I am working to creat an application where I need to have a scene where i am going to place QGraphicsItems on that scene dynamically then I need to save that scene and retrive that scene as a QGraphicsScene only wher user can modify the graphics Item again and save.
    now my code for saving is
    Qt Code:
    1. QFile file("fileName.dat");
    2. file.open(QIODevice::WriteOnly);
    3. QDataStream out(&file);
    4. if(scene->items().isEmpty()) //scene is QGraphicsScene variable
    5. return 0;
    6. else
    7. QList<QGraphicsItem *>itemsList=scene->items();
    8. out<<itemsList;
    To copy to clipboard, switch view to plain text mode 
    My code for opening the saved file is
    Qt Code:
    1. QString fileName=QFileDialog::getOpenFileName(this,tr("Open File"),QDir::currentPath()):
    2. QFile file(fileName);
    3. if(file.open(QIODevice::ReadOnly))
    4. {
    5. QMessageBox::information(this,tr("Unable to open");
    6. return 0;
    7. }
    8. else
    9. {
    10. QList<QGraphicsItem *>itemsList=scene->items();
    11. QDataStream in(&file);
    12. in>>itemsList;
    13. foreach(QGraphicsItem *item,itemList)
    14. scene->addItem(item);
    15. file.close();
    To copy to clipboard, switch view to plain text mode 
    Thats all logically I think I am Correct but I am Getting an error
    "no match for 'operator>>' in 's>>t' in qdatastream.h

    Plz help me friends where i am going wrong or is there any other method for my requirement.
    with Regards,
    srikanth
    Last edited by jpn; 27th December 2008 at 07:25. Reason: missing [code] tags

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.