-
Notifications
You must be signed in to change notification settings - Fork 0
1.06
Explanation of the contents of a topic page @ Week 1 Topic 1
Objectives: The differences between queued connections and direct connections
Comment: Thread-safe object communication: queued connections
E: Objective or new topic name?
Comment: My idea was an objective but after thinking in more detail I'd like to avoid thread-safe communication at this point. Queued connections differences to direct connections?
E: Sorted.
Comment: The important thing to learn is the "context" in which the slot is executed. The right word is thread affinity, i.e. to which thread an object belongs to. I'd like to avoid talking about thread affinity yet, so delayed creation with QMetaObject::invokeMethod(...slot...) use cases and deleteLater slot would be important to learn. In queued connections that signal parameters are always marshalled and written to the copy of the object. This is important to understand. For example signal(&MyType) cannot be connected in a queued way to a slot as copied a reference does not make sense. signal(const &MyType) on the other hand works as the object copy of the reference works as a const reference.
- What are Queued Connections?
- What can be accomplished trough Queued Connections?
- What is thread affinity?
- How connection type affects the thread affinity? (or perhaps affects the thread in which the object members are called)
- What is delayed object creation?
- What is deleteLater?
- How are Signal parameters handled in queued connections? (references actually copied)
- How do queued connections work? (QCoreApplication::postEvent)
http://doc.qt.io/qt-5/qt.html#ConnectionType-enum
E: Note that threads will come up later on the course, stick to the relevant basics of threads here and leave the in depth stuff for a later week. Keep in mind we may not discuss threads at all here if there is an approach feasible to skip threads entirely and leave them for the aforementioned later week. We could mayhaps introduce thread affinity as a picture or some kind of an info box just showing that its a thing that exists in general and that these things are related, but after that focus on the actual relevant connection stuff or something? There are probably ways to deal with this kind of stuff discretely in regards to layouting the actual material page.
Comment: If we have a simple threading app, the point is we should not subclass QThread, as in some documentation examples. We need to give a consistent message that subclassing QThread should be avoided, because it is error-prone. So, perhaps we could use QtConcurrent::run() with a QObject argument, communicating with an QObject in another thread.
http://doc.qt.io/qt-5/threads-qobject.html
https://en.wikipedia.org/wiki/Lazy_initialization (???)