-
Notifications
You must be signed in to change notification settings - Fork 0
1.11
Explanation of the contents of a topic page @ Week 1 Topic 1
Objective: Meta-type system (NOT meta-object system), File I/O
Comment: Meta-type system allows any assignable type to be known by Qt (can be used with QVariant, which can be used in QObject properties, for example). The important thing is to learn using QVariant (::value(), creation, canConvert). The second most important topic is that attendees learn how to add custom value types to QVariant, i.e. to the meta-type system. They should learn Q_DECLARE_METATYPE + its limitations. So, that in queued connections qRegisterMetaType is needed as well, because the former macro just allows using the templated functions. The third part is File I/O more like an example, how useful the variant/meta-type system is. Any registered type can be easily streamed to any I/O device.
- Can you remind me what the deal with I/O is again?
- What is QVariant?
- How to use QVariant?
- What types are supported by QVariant? (the ones registered with the meta-type system - Q_DECLARE_METATYPE)*
- What is Q_DECLARE_METATYPE and qRegisterMetaType?
- How does streaming work in QDataStream?
Comment: I'd replace Qt with QDataStream, as of course it's possible to use "generic" streaming operators in classes different from streaming operators related to the meta-object system. QDataStream is the key issue in the rest of the bullets
- How do you use basic I/O?
- What is QIODevice?
- How do you open files in Qt? Comment: should we talk about I/O devices in general?
- How do you write into files Qt? Comment: should we talk about I/O devices in general?
E: I was having some problems conceptualizing this topic so I tried throwing all the approaches at it to see what would stick :D
Comment: The big picture is the meta-type system. In Qt, each value type, used in variants, must be known by the meta-type system. New types are registered with Q_DECLARE_EMTATYPE. The idea is that each value type is known by an integer and string. For example, int equals to 42 (do not remember by heart and won't check it) and is also recognised by the string "int". This makes value types introspectable like QObject types. This is QVariant. We can introspect QVariant x; x.canConvert(); This is used by QVariant. If we want to stream a variant x, we need to register streaming operators, which makes the use if QDataSream extremely powerful. Internally, this is used in queued connections, when the value parameters are serialised into an event data and de-serialzed in the receiving thread to actual value type parameter data. Hopefully, not confusing more.
QVariant
QVariant Type Support
Streaming in QDataStream
Basic I/O (??)
QIODevice