title: const-ref when sending signals in Qt
body: <p>This is a thing that I never quite got with const-ref and I really hope that someone could explain it to me.</p>
  
  <p>When calling a function inside of another function, I get that const-ref is the best way when passing stack objects that I don't plan to tamper with. For example:</p>
  
  <pre><code>void someInnerFunction(const QString&amp; text) {
      qDebug() &lt;&lt; text;
  }
  
  void someFunction() {
      QString test = "lala";
      ....
      someInnerFunction(test);
  }
  </code></pre>
  
  <p>So far so good, I guess. But what about signals? Isn't there any risk that comes with passing a reference? Even though it's <code>const</code>. It feels like I've been reading all the docs about const-ref but I still find a bit risky since I understand it as "sending a reference to an object and keeping it <code>const</code>". What if the object it's referring to goes out of scope? </p>
  
  <p>For example:</p>
  
  <pre><code>void someFunction() {
      connect(this, SIGNAL(someSignal(const QString&amp;)), this, SLOT(someSlot(const QString&amp;)));
  
      QString test = "lala";
      emit someSignal(test);
  
      // doesnt test go out of scope here? and since im not using queued connection the QString object doesnt get copied. 
  }
  
  void someSlot(const QString&amp; test) {
      qDebug() &lt;&lt; test; // will this work?
  }
  </code></pre>
  
  <p>What is really happening here? I frequently use const-ref on function calls where I just want to access the object but not change it. But what about signals? Most signals seems to have const-ref parm in the Qt doc, but how does it work?</p>