Easy reference for implementing signal and slot

If you want trigger the execution of some task in this object from class1 object, you have to emit a signal in class1 and connect that signal to a slot in this_class.

class1.h


class class1 : public QObject
{
  Q_OBJECT
  signals:
  void signal_from_class1();

class1.cpp


class1::some_function()
{
  emit signal_from_class1();
}

this_class.h


public slots:
void slot_in_this_class();

this_class.cpp


this_class::some_function()
{
   connect(&class1_object, SIGNAL(signal_from_class1()), this, SLOT(slot_in_this_class()) );
}

void this_class::slot_in_this_class()
{
  // Do what needs to be done when the signal fires
}


Previous: How to build QT4 projects in console
Next: Two separate classes that need each other