title: Change signal-slot connection in a slot when called
body: <p>I have a use case when user actions initialise application data at each runtime. To represent that behavior here is my sample code:</p>
  
  <p><strong>SignalSlotChange.h</strong></p>
  
  <pre><code>#ifndef SIGNALSLOTCHANGE_H
  #define SIGNALSLOTCHANGE_H
  
  #include &lt;QtGui&gt;
  
  class SignalSlotChange : public QWidget
  {
  Q_OBJECT
  
  public:
      SignalSlotChange(QWidget *parent = 0);
  
  private slots:
      void firstCall();
      void secondCall();
  
  private:
      QPushButton *button;
  
  };
  
  #endif // SIGNALSLOTCHANGE_H
  </code></pre>
  
  <p><strong>SignalSlotChange.cpp</strong></p>
  
  <pre><code>#include "SignalSlotChange.h"
  
  SignalSlotChange::SignalSlotChange(QWidget *parent) : QWidget(parent)
  {
      button = new QPushButton("Messgage", this);
      QObject::connect(button, SIGNAL(clicked()), this, SLOT(firstCall()));
      show();
  }
  
  void SignalSlotChange::firstCall()
  {
      QMessageBox::information(this, "SignalSlotChange", "First call", QMessageBox::Ok, QMessageBox::NoButton);
      // Change the signal-slot connection to secondCall()
      QObject::disconnect(button, SIGNAL(clicked()), this, SLOT(firstCall()));
      QObject::connect(button, SIGNAL(clicked()), this, SLOT(secondCall()));
  }
  
  void SignalSlotChange::secondCall()
  {
      QMessageBox::information(this, "SignalSlotChange", "Second call", QMessageBox::Ok, QMessageBox::NoButton);
  }
  
  
  int main(int argc, char *argv[])
  {
      QApplication app(argc, argv);
      SignalSlotChange ssc;
      return app.exec();
  }
  </code></pre>
  
  <p>When the button is pressed then the initialising slot <code>firstCall()</code> is called. It changed the signal-slot connection to <code>secondCall()</code> for subsequent signals.</p>
  
  <p>The problem with the way I do it is that it is highly coupled and requires that slot knows exact method and signals to change it.</p>
  
  <p>With <code>QObject::sender()</code> I would know origin of sender but not its signal, and I would know about just one sender which happened to emit that signal.</p>
  
  <p>I can do it with a Boolean <code>first_call</code> but that would be making a check on Boolean value for all subsequent calls, something which I want to avoid and hence this question.</p>