Think about what you are doing in the serialization code you posted:

Qt Code:
  1. QFile file("fileName.dat");
  2. file.open(QIODevice::WriteOnly);
  3. QDataStream out(&file);
  4.  
  5. QList<QGraphicsItem *> list1= this->selectedItems();
  6. itemListSize = list1.size();
  7. out<<itemListSize;
  8. foreach( QGraphicsItem* item, list1)
  9. {
  10. out << item->x();
  11. out << item->y();
  12. }
To copy to clipboard, switch view to plain text mode 

What's going to be in this file after you are finished? In case you can't guess, it starts with an integer (the number of selected graphics items), and then continues with a series of floating point numbers, two for every item in the list. That's it. Absolutely no information about what kind of graphics item you are serializing (or even that the file results from serializing anything). So how can you possibly expect that the code that reads it in will have any clue what to do with it?

If what you want to do is save the state of the selected items to a file, and then sometime later, read that file and restore those items to exactly the same state, then, at a minimum, you need to save:

1 - the number of items (you did that part OK)
2 - for each item:

- what kind of item it is
- every property needed to re-create that item with the same appearance and put it in the right place in the scene (like, including its place in the object hierarchy)


And when you restore the items from the file, you need to reverse this process (and by the way, your de-serialization code is buggy: what happens if the currently selected items list is a different size from what is in the file, or the selected item types don't match?)

1 - read the number of items to restore
2 - for each item:

- read the item's type
- create an item of that type
- read the properties
- set the properties (correctly) on the item you just created
- add the item to the scene (in the correct place in the object hierarchy)