02-17-2013 01:45 PM
Hey Developers
How can I pass a QList as an argument with a signal? He keeps saying
"No such signal ConnectionService::downloadCompleted(QList, QString)"
I'm emitting the signal with a QList<Connection*> object and a QString. This is my signal
void downloadCompleted(const QList<Connection*> &connections, const QString &error);
And this is how I connect
connect(&this->connectionService, SIGNAL(downloadCompleted(QList, QString)), this, SLOT(searchCompleted(QList, QString)));
I allso tried QList<Connection*> as SIGNAL signature. But that did not work either.
Thanks in advance.
Solved! Go to Solution.
02-17-2013 01:53 PM - edited 02-17-2013 01:58 PM
Pass a complete type, i.e.
connect(&connectionService, SIGNAL(downloadCompleted(const QList<Connection*>&, const QString&)), this, SLOT(searchCompleted(const QList<Connection *>&, const QString&)));
"const" and "&" can be omitted so this should also work:
connect(&connectionService, SIGNAL(downloadCompleted(QList<Connection*>, QString)), this, SLOT(searchCompleted(QList<Connection *>, QString)));
upd:
Try registering the type:
qRegisterMetaType< QList<Connection *> >("QList<Connection *>");
02-17-2013 02:03 PM
That's weird, I thought I allready tried that. But hey, it works, I'm happy
.
Thanks again!
02-17-2013 02:09 PM
And is it also possible to do it like this:
void downloadCompleted(const QList<Connection*> *connections, const QString &error);
connect(&connectionService, SIGNAL(downloadCompleted(QList<Connection*>*, QString)), this, SLOT(searchCompleted(QList<Connection*>*, QString)));
Because that does not seem to work anymore. Don't know if it's possible to pass a pointer with a signal.
02-17-2013 02:12 PM - edited 02-17-2013 02:15 PM
Try registering QList<Connection *>* using qRegisterMetatype. It should work, but I think it's better to pass QList itself so you don't have to track it's lifetime.
Qt containers are copy-on-write anyway so this operation shouldn't be time consuming.
Even foreach() makes a copy of it's container before iteration. ![]()