Results 1 to 6 of 6

Thread: QSettings from stream

  1. #1
    Join Date
    Apr 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Maemo/MeeGo

    Question QSettings from stream

    I have a custom datatype called "Repository", which has a QSettings object as a member. I'm implementing the >> stream operator and having trouble while retrieving the QSettings object from the stream as I can't stream directly to QSettings (or so it seems). Is it possible to stream data to a QSettings object? If so, how should I proceed?

    The relevant code is:
    Qt Code:
    1. class Repository::Private {
    2. public:
    3. QString location;
    4. QSettings* settings;
    5.  
    6. Private()
    7. : location()
    8. , settings(0)
    9. {}
    10. };
    11.  
    12. Repository::Repository(QObject *parent)
    13. : QObject(parent)
    14. , data(new Private)
    15. {}
    16.  
    17. QDataStream& operator>> (QDataStream& stream, Repository::Ptr& repository)
    18. {
    19. QString location;
    20. QSettings* settings;
    21.  
    22. stream >> location;
    23. stream >> settings; /* Can't stream to QSettings */
    24.  
    25. if (stream.status() != QDataStream::Ok) {
    26. Core::EncodingError e;
    27. e.setDescription("The policy configuration could not be decoded");
    28. throw e;
    29. }
    30. repository->data->location = location;
    31. repository->data->settings = settings;
    32.  
    33. return stream;
    34. }
    To copy to clipboard, switch view to plain text mode 

    The error message:
    Qt Code:
    1. ../../../Workdir/policy-control/policy-control/policy/repository.cpp: In function ‘QDataStream& Policy::operator>>(QDataStream&, Policy::Repository*&)’:
    2. ../../../Workdir/policy-control/policy-control/policy/repository.cpp:517: error: no match for ‘operator>>’ in ‘stream >> settings’
    3. ../../../install/qtsdk-2010.02/qt/include/QtCore/qdatastream.h:141: note: candidates are: QDataStream& QDataStream::operator>>(qint8&)
    4. ../../../install/qtsdk-2010.02/qt/include/QtCore/qdatastream.h:215: note: QDataStream& QDataStream::operator>>(quint8&)
    5. ../../../install/qtsdk-2010.02/qt/include/QtCore/qdatastream.h:143: note: QDataStream& QDataStream::operator>>(qint16&)
    6. ../../../install/qtsdk-2010.02/qt/include/QtCore/qdatastream.h:218: note: QDataStream& QDataStream::operator>>(quint16&)
    7. ../../../install/qtsdk-2010.02/qt/include/QtCore/qdatastream.h:145: note: QDataStream& QDataStream::operator>>(qint32&)
    8. ../../../install/qtsdk-2010.02/qt/include/QtCore/qdatastream.h:221: note: QDataStream& QDataStream::operator>>(quint32&)
    9. ../../../install/qtsdk-2010.02/qt/include/QtCore/qdatastream.h:147: note: QDataStream& QDataStream::operator>>(qint64&)
    10. ../../../install/qtsdk-2010.02/qt/include/QtCore/qdatastream.h:224: note: QDataStream& QDataStream::operator>>(quint64&)
    11. ../../../install/qtsdk-2010.02/qt/include/QtCore/qdatastream.h:150: note: QDataStream& QDataStream::operator>>(bool&)
    12. ../../../install/qtsdk-2010.02/qt/include/QtCore/qdatastream.h:151: note: QDataStream& QDataStream::operator>>(float&)
    13. ../../../install/qtsdk-2010.02/qt/include/QtCore/qdatastream.h:152: note: QDataStream& QDataStream::operator>>(double&)
    14. ../../../install/qtsdk-2010.02/qt/include/QtCore/qdatastream.h:153: note: QDataStream& QDataStream::operator>>(char*&)
    15. ../../../Workdir/policy-control/policy-control/policy/repository.cpp:499: note: QDataStream& Policy::operator>>(QDataStream&, Policy::Repository*&)
    16. ../../../install/qtsdk-2010.02/qt/include/QtCore/quuid.h:183: note: QDataStream& operator>>(QDataStream&, QUuid&)
    17. ../../../install/qtsdk-2010.02/qt/include/QtCore/qrect.h:622: note: QDataStream& operator>>(QDataStream&, QRectF&)
    18. ../../../install/qtsdk-2010.02/qt/include/QtCore/qrect.h:200: note: QDataStream& operator>>(QDataStream&, QRect&)
    19. ../../../install/qtsdk-2010.02/qt/include/QtCore/qsize.h:256: note: QDataStream& operator>>(QDataStream&, QSizeF&)
    20. ../../../install/qtsdk-2010.02/qt/include/QtCore/qsize.h:103: note: QDataStream& operator>>(QDataStream&, QSize&)
    21. ../../../install/qtsdk-2010.02/qt/include/QtCore/qline.h:417: note: QDataStream& operator>>(QDataStream&, QLineF&)
    22. ../../../install/qtsdk-2010.02/qt/include/QtCore/qline.h:206: note: QDataStream& operator>>(QDataStream&, QLine&)
    23. ../../../install/qtsdk-2010.02/qt/include/QtCore/qpoint.h:238: note: QDataStream& operator>>(QDataStream&, QPointF&)
    24. ../../../install/qtsdk-2010.02/qt/include/QtCore/qpoint.h:104: note: QDataStream& operator>>(QDataStream&, QPoint&)
    25. ../../../install/qtsdk-2010.02/qt/include/QtCore/qdatetime.h:321: note: QDataStream& operator>>(QDataStream&, QDateTime&)
    26. ../../../install/qtsdk-2010.02/qt/include/QtCore/qdatetime.h:319: note: QDataStream& operator>>(QDataStream&, QTime&)
    27. ../../../install/qtsdk-2010.02/qt/include/QtCore/qdatetime.h:317: note: QDataStream& operator>>(QDataStream&, QDate&)
    28. ../../../install/qtsdk-2010.02/qt/include/QtCore/qbitarray.h:164: note: QDataStream& operator>>(QDataStream&, QBitArray&)
    29. ../../../install/qtsdk-2010.02/qt/include/QtCore/qurl.h:277: note: QDataStream& operator>>(QDataStream&, QUrl&)
    30. ../../../install/qtsdk-2010.02/qt/include/QtCore/qvariant.h:531: note: QDataStream& operator>>(QDataStream&, QVariant::Type&)
    31. ../../../install/qtsdk-2010.02/qt/include/QtCore/qvariant.h:529: note: QDataStream& operator>>(QDataStream&, QVariant&)
    32. ../../../install/qtsdk-2010.02/qt/include/QtCore/qtextstream.h:287: note: QTextStream& operator>>(QTextStream&, QTextStream& (*)(QTextStream&))
    33. ../../../install/qtsdk-2010.02/qt/include/QtCore/qlocale.h:669: note: QDataStream& operator>>(QDataStream&, QLocale&)
    34. ../../../install/qtsdk-2010.02/qt/include/QtCore/qstringlist.h:245: note: QDataStream& operator>>(QDataStream&, QStringList&)
    35. ../../../install/qtsdk-2010.02/qt/include/QtCore/qregexp.h:155: note: QDataStream& operator>>(QDataStream&, QRegExp&)
    36. ../../../install/qtsdk-2010.02/qt/include/QtCore/qstring.h:1070: note: QDataStream& operator>>(QDataStream&, QString&)
    37. ../../../install/qtsdk-2010.02/qt/include/QtCore/qbytearray.h:577: note: QDataStream& operator>>(QDataStream&, QByteArray&)
    38. ../../../install/qtsdk-2010.02/qt/include/QtCore/qchar.h:390: note: QDataStream& operator>>(QDataStream&, QChar&)
    39. ../../../Workdir/policy-control/policy-control/policy/repository.cpp:510: warning: unused variable ‘m_effectiveCurrentPolicyOrigin’
    40. make[1]: *** [repository.o] Error 1
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings from stream

    A solution could be save the contents of DataStream in a QTemporaryFile and read it with QSettings
    A camel can go 14 days without drink,
    I can't!!!

  3. #3

    Default Re: QSettings from stream

    Hi

    I want to use QSettings in the same way too. Solution using temporary file doesn't like me a lot. I checked the source code of this object but it seem there is no way also ereditating the class. Someone know how is possible to use QSettings object in such streaming way?

    Thank you

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings from stream

    The code in this thread is invalid. Streaming to a pointer to an object doesn't make sense. At best you'll get an address the settings object had when it was being serialized. This address will not be valid anymore of course.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5

    Default Re: QSettings from stream

    Hi

    Regarding my needs (that could be different from the original author of this thread) I want to download a remote file from a web site. This file will have a ini format in the body but since I download the content of them I have in memory the full body and I want to parse it using QSettings object. Using stream way was the first idea I had but every suggestion is welcomed. Basically I have a string formatted in ini format, how can I pass this string to QSettings jumping the steps save to a file/read from file?

    Thank you

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings from stream

    Streaming won't help you here. What you need to do is to work around QFile API so that QFile thinks your memory buffer is a real file. To do that you need to implement QAbstractFileEngine interface that will wrap your memory buffer. However this is more work than implementing your own ini parser.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Best way to stream and record a webcam
    By ichigo in forum Qt Programming
    Replies: 4
    Last Post: 27th June 2014, 23:51
  2. Replies: 1
    Last Post: 14th January 2011, 11:57
  3. Xml stream
    By rk0747 in forum Qt Programming
    Replies: 3
    Last Post: 9th February 2010, 18:10
  4. QGraphicScene to stream
    By phannent in forum Newbie
    Replies: 2
    Last Post: 28th June 2008, 09:43
  5. Migrate Qt3 QSettings to Qt4 QSettings
    By hvengel in forum Qt Programming
    Replies: 3
    Last Post: 22nd February 2008, 03:21

Tags for this Thread

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.