Destruction of a slot's local variables in an event loop
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.
Code:
MyWidget
::MyWidget(QWidget *parent
){
// ...
connect(pb_browse, SIGNAL(clicked()),
this, SLOT(selectFile()));
connect(this,
SIGNAL(selected
(const QString &)),
le_path,
SLOT(setText
(const QString &)));
}
Code:
// A slot
void MyWidget::selectFile()
{
emit(selected(path));
}
Re: Destruction of a slot's local variables in an event loop
When connection signal/slot is created as not Qt::QueuedConnection then emit signal is equivalent of calling method (slot). When connection is creted as Qt::QueuedConnection then signal engine creates copy of all parameters. Therefore in Qt::QueuedConnection signals You can use only registered meta types.