c++ - Why are Qt signals NOT const -


qt uses signals , slots object communication. signals declared member function , qt moc generates definition of function.

what understand why signals not const member functions?

edit: expect signals not modify sender, that's why question.

i expect signals not modify sender

signals (as generated moc) not directly modify class instance' members. generated code, however, passes this pointer along, consumption (potential) slot. connected slot mutate sender of signal.

so technical reason is, if signals const, require slot implementations call const class members on sender code compile without errors.

implementing signals non-const class members understandable decision, respect code safety. still feels unnatural in number of cases (e.g. if connected slot implemented in same class const, or if connected slot belongs object altogether).


Comments