title: Create a flag for a Qt project or use QLoggingCategory
body: <p>This is my first question on this website, I hope I'll do it just fine.</p>
  
  <p>I'm doing a Qt Project at work using a lot of signals and slots and I would like to <strong>create a flag/macro/variable to activate/deactivate the use of std::cout to trace which signal is emitted and which slot is activated</strong>.</p>
  
  <p>This is for debugging purpose, to know how the different components of the application exchange and avoid loops in signals/slots.</p>
  
  <p>More specifically, I would have a flag/variable in my .pro :</p>
  
  <pre><code>QT_SIGNALS_SLOTS_LOG = true
  </code></pre>
  
  <p>and in my source code :</p>
  
  <pre><code>if(QT_SIGNALS_SLOTS_LOG)
       std::cout &lt;&lt; "MyClass::slotMySlot activated" &lt;&lt; std::endl;
  </code></pre>
  
  <p>Questions :</p>
  
  <p><strong>1.</strong> Can I do something like that (using a variable of the .pro in the
      code) ?</p>
  
  <p><strong>2.</strong> Is there a better way of doing that ?</p>
  
  <hr>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>Burich, this works just fine, thanks</p>
  
  <p>Now I will try to code a Qt macro which I put in my slots and wich does all the work</p>
  
  <p>Example :</p>
  
  <pre><code>Q_SIGNALS_SLOTS_LOG();
  </code></pre>
  
  <p>which gets the names of the Class and the Slot and do the</p>
  
  <pre><code>ifdef QT_SIGNALS_SLOTS_LOG
       std::cout &lt;&lt; "MyClass::slotMySlot activated" &lt;&lt; std::endl;
  endif
  </code></pre>
  
  <p>Is there a way of doing that ?</p>
  
  <hr>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>I used <a href="https://doc.qt.io/qt-5/qloggingcategory.html#details" rel="nofollow">QLoggingCategory Class</a> with this <a href="http://blog.qt.io/blog/2014/03/11/qt-weekly-1-categorized-logging/" rel="nofollow">tutorial</a></p>
  
  <p>I have a Class in my Utils folder with this code</p>
  
  <pre><code>#ifndef SIGNALSLOTDEBUG_H
  #define SIGNALSLOTDEBUG_H
  #include&lt;QLoggingCategory&gt;
  
  
  Q_DECLARE_LOGGING_CATEGORY(logSignal)
  Q_DECLARE_LOGGING_CATEGORY(logSlot)
  
  inline static void debugSlotF( char const * caller_name )
  {
      qCDebug(logSlot) &lt;&lt; __TIME__ &lt;&lt; caller_name &lt;&lt; "activated";
  }
  
  inline static void debugSlot(){
  
  }
  
  #define debugSlot() debugSlotF(__PRETTY_FUNCTION__)
  
  #endif // SIGNALSLOTDEBUG_H
  </code></pre>
  
  <p>In my code I just call</p>
  
  <pre><code>void HorizontalPatternListScene::slotSelectionChanged(int i)
  {
      debugSlot();
      ....
  </code></pre>
  
  <p>I get this output :</p>
  
  <pre><code>log.slot: 12:06:54 void HorizontalPatternListScene::slotSelectionChanged(int) activated
  </code></pre>
  
  <p>And I can disable the stream by doing </p>
  
  <pre><code>QLoggingCategory::setFilterRules(
              "log.slot=true\n"
              "log.signal=false");
  </code></pre>
  
  <p>in my main.cpp</p>