title: How to use QMutex?
body: <p>I'm newbie to Qt and I'm looking for multi-threading in Qt.<br>
  As I learned in <a href="https://doc.qt.io/archives/qt-4.8/threads-starting.html" rel="nofollow noreferrer">Qt Documents</a>, I defined two class for two thread:</p>
  
  <pre><code>#include &lt;QThread&gt;
  #include &lt;QMutex&gt;
  
  class thread_a : public QThread
  {
      Q_OBJECT
  public:
      explicit thread_a(QObject *parent = 0);
      int counter;
  
  protected:
      void run();
  };
  </code></pre>
  
  <p>And in CPP file:</p>
  
  <pre><code>#include "thread_a.h"
  
  thread_a::thread_a(QObject *parent) :
      QThread(parent)
  {
      counter=0;
  }
  
  void thread_a::run()
  {
      counter++;
  }
  </code></pre>
  
  <p>Second thread class is same, but with <code>counter--</code> in <code>run()</code> method.<br>
  Then I run this two threads from <code>main.ccp</code>.</p>
  
  <p>Now my question:<br>
  How can I share <code>counter</code> in <code>thread_a</code> and <code>thread_b</code> using <code>QMutex</code>?</p>