serializerrunnable.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef SERIALIZERRUNNABLE_H
  2. #define SERIALIZERRUNNABLE_H
  3. #include <QtCore/qglobal.h>
  4. #include <QtCore/QObject>
  5. #include <QtCore/QRunnable>
  6. class QByteArray;
  7. class QString;
  8. class QVariant;
  9. namespace QJson {
  10. /**
  11. * @brief Convenience class for converting JSON data to QVariant objects using a dedicated thread
  12. */
  13. class SerializerRunnable : public QObject, public QRunnable
  14. {
  15. Q_OBJECT
  16. public:
  17. /**
  18. * This signal is emitted when the conversion process has been completed
  19. * @param data contains the JSON data that has to be converted
  20. * @param parent parent of the object
  21. **/
  22. explicit SerializerRunnable(QObject* parent = 0);
  23. ~SerializerRunnable();
  24. /**
  25. * Sets the json object to serialize.
  26. *
  27. * @param json QVariant containing the json representation to be serialized
  28. */
  29. void setJsonObject( const QVariant& json );
  30. /* reimp */ void run();
  31. Q_SIGNALS:
  32. /**
  33. * This signal is emitted when the serialization process has been completed
  34. * @param serialized contains the result of the serialization
  35. * @param ok if a serialization error occurs ok is set to false, otherwise it's set to true.
  36. * @param error_msg contains a string explaining the failure reason
  37. **/
  38. void parsingFinished(const QByteArray& serialized, bool ok, const QString& error_msg);
  39. private:
  40. Q_DISABLE_COPY(SerializerRunnable)
  41. class Private;
  42. Private* const d;
  43. };
  44. }
  45. #endif // SERIALIZERRUNNABLE_H