Results 1 to 2 of 2

Thread: Sérialization, QVariant et QSettings : unable*to*load*type 257

  1. #1
    Join Date
    Mar 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Sérialization, QVariant et QSettings : unable*to*load*type 257

    Hello

    I experience issues when running my application

    I have personnal object (ChannelObjectSerializable) which I want to save status.

    Here is part of the code which will help :

    After the sync() :


    Qt Code:
    1. QVariant::load: unable to load type 257.
    2. QVariant::save: unable to save type 257.
    3. QVariant::load: unable to load type 257.
    4. #####################
    5. # Channel :
    6. # #
    7. # #
    8. # #
    9. # #
    10. # #
    11. #####################
    To copy to clipboard, switch view to plain text mode 

    Avec :

    ChannelObjectSerilizable.h
    Qt Code:
    1. private:
    2. friend QDataStream & operator << (QDataStream &, const ChannelObjectSerializable &);
    3. friend QDataStream & operator >> (QDataStream &, ChannelObjectSerializable &);
    4. };
    5.  
    6. Q_DECLARE_METATYPE(ChannelObjectSerializable)
    7. QDataStream & operator << (QDataStream & out, const ChannelObjectSerializable & Valeur);
    8. QDataStream & operator >> (QDataStream & in, ChannelObjectSerializable & Valeur);
    To copy to clipboard, switch view to plain text mode 

    ChannelObjectSerializable.cpp :
    Qt Code:
    1. void ChannelObjectSerializable::initChannelSystem()
    2. {
    3. qRegisterMetaTypeStreamOperators("ChannelObject");
    4. qMetaTypeId();
    5. }
    6.  
    7. QDataStream & operator<<(QDataStream & out, const ChannelObjectSerializable & Valeur)
    8. {
    9. QString tmp;
    10. out << tmp.fromStdString(Valeur.nom)
    11. << tmp.fromStdString(Valeur.lastUpdate)
    12. << tmp.fromStdString(Valeur.description)
    13. << tmp.fromStdString(Valeur.lien)
    14. << tmp.fromStdString(Valeur.link);
    15.  
    16. return out;
    17. }
    18.  
    19. QDataStream & operator>>(QDataStream & in, ChannelObjectSerializable & Valeur)
    20. {
    21. QString tmp;
    22. in >> tmp;
    23. Valeur.nom = tmp.toStdString();
    24. in >> tmp;
    25. Valeur.lastUpdate = tmp.toStdString();
    26. in >> tmp;
    27. Valeur.description = tmp.toStdString();
    28. in >> tmp;
    29. Valeur.lien = tmp.toStdString();
    30. in >> tmp;
    31. Valeur.link = tmp.toStdString();
    32.  
    33. return in;
    34. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. ChannelObjectSerializable p = ChannelObjectSerializable(newRSS);
    2. p.initChannelSystem();
    3. QSettings fichier_ecrire("Test.ini", QSettings::IniFormat);
    4. fichier_ecrire.setValue("channel", qVariantFromValue(p));
    5. p.printDonnees();
    6. fichier_ecrire.sync();
    7.  
    8. ChannelObjectSerializable copie;
    9. QSettings fichier_lire("Test.ini", QSettings::IniFormat);
    10. copie = fichier_lire.value("channel", qVariantFromValue(ChannelObjectSerializable())).value();
    11. copie.printDonnees();
    To copy to clipboard, switch view to plain text mode 



    After loading the object, it's empty

  2. #2
    Join Date
    Mar 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Sérialization, QVariant et QSettings : unable*to*load*type 257


Similar Threads

  1. Using QVariant with custom data type
    By QAlex in forum Qt Programming
    Replies: 3
    Last Post: 4th December 2009, 12:04
  2. Unable to define a new type with QVariant
    By max2g in forum Qt Programming
    Replies: 3
    Last Post: 23rd February 2008, 17:55
  3. QSettings and new QVariant Type
    By baray98 in forum Qt Programming
    Replies: 7
    Last Post: 11th February 2008, 11:40
  4. Unable to load jpg on Mac OS
    By sgmurphy19 in forum Qt Programming
    Replies: 14
    Last Post: 31st January 2008, 12:49
  5. QVariant, QList, QSettings
    By TheKedge in forum Qt Programming
    Replies: 6
    Last Post: 6th March 2007, 15:50

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.