23

I found myself in the need of having to call a slot directly. I think it's perfectly fine doing it as long as it makes sense in your design. What do you think?

Thanks

Daniel
  • 561
  • 1
  • 4
  • 17

1 Answers1

44

Yes.. Slots are just normal functions and you can call them directly..

From docs,

A slot is called when a signal connected to it is emitted. Slots are normal C++ functions and can be called normally; their only special feature is that signals can be connected to them.

feedc0de
  • 3,646
  • 8
  • 30
  • 55
liaK
  • 11,422
  • 11
  • 48
  • 73
  • 1
    I know they can be called normally. I read the documentation as well. But the question is more a design than a C++ question. – Daniel Oct 18 '10 at 18:05
  • 11
    Problem is multithreading. If you call a slot directly the executing thread might be different from the executing would you have used connect() (if the object of the slot was moved to another thread before). See also http://stackoverflow.com/questions/1144240/qt-how-to-call-slot-from-custom-c-code-running-in-a-different-thread – NoDataDumpNoContribution Apr 16 '14 at 14:13