Results 1 to 4 of 4

Thread: Saving / Loading Files

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Saving / Loading Files

    To answer your first question, I think you are abusing XML by filling it with base64-encoded gobbledygook. Either use XML with a human-readable format or switch to a binary format altogether.

    About your second question. Have a look at http://www.qtcentre.org/wiki/index.p...GUI_Responsive to review your options. If you end up choosing the worker thread route, you will face Qt's not-so-up-to-date documentation on the subject. Many threads on this forum deal with the problem of communication between threads so you could start from here.

  2. #2
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Saving / Loading Files

    Hello there,
    thanks for advice, I changed my approach so i'm keeping shapes into a binary files like that QVector< QVector< Shape *> > i'm serializing as like that. ContentManager is a QThread class.

    Qt Code:
    1. bool ContentManager::load(const QString &fileName)
    2. {
    3. s_mutex.lock();
    4. m_shapesFile->setFileName("c:/shapes.txt");
    5. if (!m_shapesFile->open( QIODevice::ReadOnly )) {
    6. return false;
    7. }
    8.  
    9. QDataStream dsFile( m_shapesFile );
    10. int boardCount;
    11. int shapeCount;
    12. int type;
    13. dsFile >> sceneCount;
    14. for (int i = 0; i < sceneCount; ++i)
    15. {
    16. dsFile >> shapeCount;
    17. for (int j = 0; j < shapeCount; ++j)
    18. {
    19. dsFile >> type;
    20. Shape *_s = new StrokeItem(); // TEST
    21. dsFile >> _s; // TEST
    22. delete _s; // TEST
    23. }
    24. }
    25. qDebug() << "done";
    26. m_shapesFile->close()
    27. s_mutex.unlock();
    28. return true;
    29. }
    To copy to clipboard, switch view to plain text mode 

    Thus, I can read whole file correct as like that. So this is the question. What i must to do in TEST step. I can send binary data through signal to GUI thread and then de-serialize that QDataStream and then add that item into Scene or i can create new Shape *_s = new ... then Sending through that item into GUI thread then directl i can add this item into scene , What do you suggest for that, or do you have another an idea ?
    Last edited by nightroad; 26th August 2011 at 13:18.

Similar Threads

  1. Prevent saving files to System folders
    By ScottBrady in forum Newbie
    Replies: 8
    Last Post: 13th August 2011, 15:19
  2. Problem when saving bmp files
    By cdlaweed in forum Newbie
    Replies: 3
    Last Post: 17th March 2011, 09:20
  3. Replies: 20
    Last Post: 22nd February 2011, 17:01
  4. Loading and saving in-memory SQLITE databases
    By miraks in forum Qt Programming
    Replies: 10
    Last Post: 27th April 2010, 21:24
  5. QDataStream and saving and loading QList
    By Noxxik in forum Qt Programming
    Replies: 3
    Last Post: 1st March 2009, 22:02

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.