what's the correct way to emit a signal with a QString if that QString is local. I mean, I have such a function in wigdetA
void wigdetA::something() { // //eg // QTreeWidgetItem *it = this->treeWidget->currentItem(); if (it == 0) return; QString s = it->text(1); emit passToMainWindow(s); }
Should I create a connection like this (just const QString):
connect(wigdetA, SIGNAL(passToMainWindow(const QString)), this, SLOT(passToMainWindow(const QString)));
or i can use a constant link
connect(wigdetA, SIGNAL(passToMainWindow(const QString&)), this, SLOT(passToMainWindow(const QString&)));
Both methods work, but I, although the second const & will cause the application to crash, since QString s is local, and it will be destroyed when the something () function exits.
or am I missing something?
source share