title: QMutex in slots
body: <p>Suppose to have the following QT code (QT 5.3.1):</p>
  
  <pre><code>void SenderClass::runSignal()
  {
      emit mySignal();
  }
  
  void ReceiverClass::ReceiverClass()
  {
      ...
      connect (senderClassRef, SIGNAL(mySignal()), this, SLOT(mySlot()) );
  }
  
  void ReceiverClass::mySlot()
  {
      //Long operation executions
      Sleep(1000);
      qDebug() &lt;&lt; "1";
      Sleep(1000);
      qDebug() &lt;&lt; "2";
      Sleep(1000);
      qDebug() &lt;&lt; "3";
  }
  </code></pre>
  
  <p>Calling runSignal() consecutively it happens that console displays something like:</p>
  
  <blockquote>
    <p>1 2 1 3 2 3</p>
  </blockquote>
  
  <p>The 2 classes live in the same thread.
  Do I have to use a QMutexLocker in slots?? Or is there an another way to have an ordered output like: </p>
  
  <blockquote>
    <p>1 2 3 1 2 3</p>
  </blockquote>
  
  <p>so preventing a call of <em>mySlot()</em> function if there's still one executing.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Here follow a real code snippet.
  The sender:</p>
  
  <pre><code>//Sender.h
  
  #include &lt;QtWidgets/QWidget&gt;
  #include &lt;QtWidgets/QPushButton&gt;
  #include &lt;QtWidgets/QTextBrowser&gt;
  
  class Receiver;
  
  class Sender : public QWidget
  {
      Q_OBJECT
  
  public:
      Sender(QWidget *parent = 0);
  
      QPushButton *pushButton;
      QTextBrowser *textBrowser;
      Receiver* receiver;
  
  signals:
      void buttonClickedSignal();
  
  public slots:
      void ButtonClickedSlot();
  };
  
  //Sender.cpp
  
  #include "Sender.h"
  #include "Receiver.h"
  
  #include &lt;QObject&gt;
  
  Sender::Sender(QWidget *parent)
      : QWidget(parent)
  {
      pushButton = new QPushButton(this);
      pushButton-&gt;setObjectName(QStringLiteral("pushButton"));
      pushButton-&gt;setGeometry(QRect(150, 30, 75, 23));
      pushButton-&gt;setText("Button");
      textBrowser = new QTextBrowser(this);
      textBrowser-&gt;setObjectName(QStringLiteral("textBrowser"));
      textBrowser-&gt;setGeometry(QRect(50, 90, 256, 192));
  
      receiver = new Receiver(this);
  
      QObject::connect(pushButton, SIGNAL(clicked()), this, SLOT(ButtonClickedSlot()));
  }
  
  void Sender::ButtonClickedSlot()
  {
      emit buttonClickedSignal();
  }
  </code></pre>
  
  <p>The receiver:</p>
  
  <pre><code>//Receiver.h
  #include "Sender.h"
  
  class Receiver : QObject
  {
      Q_OBJECT
  
  public:
      Receiver(Sender *sender);
  
      Sender *m_sender;
  
  public slots:
      void ReceiverSlot();
  };
  
  //Receiver.cpp
  #include "Receiver.h"
  
  #include &lt;QObject&gt;
  #include &lt;QThread&gt;
  #include &lt;QApplication&gt;
  
  Receiver::Receiver(Sender *sender)
  {
      m_sender = sender;
  
      QObject::connect(m_sender, SIGNAL(buttonClickedSignal()), this, SLOT(ReceiverSlot()), Qt::QueuedConnection);
  }
  
  void Receiver::ReceiverSlot()
  {
      m_sender-&gt;textBrowser-&gt;append("1");
      QThread::msleep(100);
      qApp-&gt;processEvents();
      m_sender-&gt;textBrowser-&gt;append("2");
      QThread::msleep(100);
      qApp-&gt;processEvents();
      m_sender-&gt;textBrowser-&gt;append("3");
      QThread::msleep(100);
      qApp-&gt;processEvents();
      m_sender-&gt;textBrowser-&gt;append("4");
      QThread::msleep(100);
      qApp-&gt;processEvents();
  }
  </code></pre>
  
  <p>Clicking the button quickly results in not consecutive numbers in QTextBrowser, even if a QueuedConnection is set.</p>
  
  <p><img src="https://i.stack.imgur.com/VUN2x.png" alt="Output"></p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>What I would like to achieve is a queued access to the ReceiverSlot. The user can click the button with any freedom (when he wants and at any speed). The ReceiverSlot cannot miss any event. I need some sort of event queuing so that (long) operations in the ReceiverSlot are always executed, maybe delayed, but executed.</p>