Hi all,

Is it safe to assume that a slot's local variables will be valid until the end of the event loop?

For example, is it safe to emit a reference to a local variable (see below)? All of Qt's official examples (that I've seen) for signals/slots that involve QString seem to pass them by reference. My short tests with this code also seemed to work fine in Windows 7 and Linux, but I can't help wondering if there's a risk that selectFile() will return (and "path" gets destroyed) before the string can be processed.

Qt Code:
  1. MyWidget::MyWidget(QWidget *parent)
  2. {
  3. QPushButton *pb_browse = new QPushButton("...", this);
  4. QLineEdit *le_path = new QLineEdit(this);
  5.  
  6. // ...
  7.  
  8. connect(pb_browse, SIGNAL(clicked()),
  9. this, SLOT(selectFile()));
  10. connect(this, SIGNAL(selected(const QString &)),
  11. le_path, SLOT(setText(const QString &)));
  12. }
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. // A slot
  2. void MyWidget::selectFile()
  3. {
  4. QString path = QFileDialog::getOpenFileName(this, "Select a file");
  5.  
  6. emit(selected(path));
  7. }
To copy to clipboard, switch view to plain text mode