In my qt application i have a class (worker) which is called from the object which runs in a thread. In my worker class i create QList, like this
QList <QString> albums;
while (i.hasNext())
{
QRegularExpressionMatch album = i.next();
albums.append(album.captured("album"));
}
emit SignalGotAlbums(albums);
I receive this signal in another class which is wrapping my worker, for thread-usage. Let's call this class GetAlbumsThread. In there i successfully receive SignalGotAlbums in a slot
void GetAlbumsThread::Reply(QList <QString> &list)
{
emit gotAlbums(list);
emit finished();
}
In this slot i'am firing another signal gotAlbums which is suppose to be connected with a slot in my gui thread, and pass my QList in there. My problem is, when im trying to pass QList from a thread to gui, it's just not working! Slot not receiving gotAlbums Signal;
Signal is declared like so:
void gotAlbums(QList<QString> &);
And connected to my gui slot (of course in my gui thread) like that:
private slots:
void AlbumsReceived(QList<QString> &list)
...
QThread* albumsThread = new QThread();
GetAlbumsThread *albumsObject = new GetAlbumsThread();
albumsObject->moveToThread(albumsThread);
connect(albumsThread, SIGNAL(started()), albumsObject, SLOT(process()));
connect(albumsObject, SIGNAL(gotAlbums(QList<QString> &)), this, SLOT(AlbumsReceived(QList<QString> &));
albumsThread->start();
AlbumsReceived never get's called for some reason. connect returns true. Can someone help me with this. I think the problem is in the passing QList between threads.
Did you try to register your QList object before calling Object::connect(...) ?
You can declare the meta-type using this code:
qRegisterMetaType< QList<QString> >( "QList<QString>" );