-1

I have some confusing questions on Qt signals.

(1) Assume A is B's parent. B emits a signal. Does the signal go to A? Use some code to explain my questions.

connect(B, SIGNAL(B_signal()), C, SLOT(C_slot())); 
connect(A, SIGNAL(B_signal()), C, SLOT(C_slot()));

Is the second line valid?

(2) If A is derived from B, does A have B's signals?

Thanks.

user1899020
  • 13,167
  • 21
  • 79
  • 154
  • 1
    there are gozillion of questions already asked ... here is one http://stackoverflow.com/questions/1368593/qt-question-how-do-signals-and-slots-work – user1824407 Jan 09 '13 at 21:39
  • Are they same questions? – user1899020 Jan 09 '13 at 23:00
  • @user1899020 It's the same question as your post title, but then you ask two different questions in the post body. – cmannett85 Jan 09 '13 at 23:33
  • you should be more clear about what you are asking, anyway if the QT signal/slot system doesn't feet your needs you can simply use another one, using the QT signal/slot system when working with QT it's not mandatory. – user1824407 Jan 10 '13 at 00:11

1 Answers1

2

This is my understanding of the subject:

(1) No, second line is not valid. Child-parent relationship is used to define the hierarchy of the objects - it allows retrieving all children of the object/ parent of an object, which allows automatically performing some operations on branches of hierarchy tree - say deleting all children of the object when object is being deleted, and so on. However, signals and slots belong to each particular object. When signal is being emitted, it is being processed by event loop of the thread the object lives in.

(2) Yes, in that case A has all signals, slots, methods and member variables of B, in case of inheritance you can think of it as B being a part of A.

Ilya Kobelevskiy
  • 5,245
  • 4
  • 24
  • 41
  • 1
    "When signal is being emitted, it is being processed by event loop of the thread the object lives in." - that's true, for the same-thread use case (the vast majority of signal/slot connections), there's no event loop involved though, it's just plain synchronous function calls. – Frank Osterfeld Jan 09 '13 at 22:25