Reputation: 9141
I'm not able to receive my custom signal in the supposed SLOT
. Here is my code:
mainwindow.h
:
class HistoryItem {
public:
QString channel;
};
class dbThread : public QObject
{
Q_OBJECT
public:
dbThread();
signals:
void historyLoaded(QList<HistoryItem*> innerResult);
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void historyLoaded(const QList<HistoryItem*> innerResult);
mainwindow.cpp
:
connect(dbtrad, SIGNAL(historyLoaded(QList<HistoryItem*>*)), this, SLOT(historyLoaded(QList<HistoryItem*>*)));
void MainWindow::historyLoaded(QList<HistoryItem*> innerResult) {
qDebug() << "historyLoaded()...";
}
And this is how I emit the signal:
QList<HistoryItem*> innerResult;
while (queryInner.next()) {
QString channelIDInner = queryInner.value(0).toString();
HistoryItem* item = new HistoryItem();
item->channel = channelIDInner;
innerResult.append(item);
}
qDebug() << "DONE LOADING.....";
emit historyLoaded(innerResult);
However, qDebug() << "historyLoaded()...";
is never executed.
Any ideas what the problem could be?
Upvotes: 2
Views: 8069
Reputation: 12931
It seems you're using threads. Using QList
when signaling across threads (or using Qt::QueuedConnection
in general) requires some extra work. Basically you need to define the QList<T>
type using typedef
and then register it using qRegisterMetaType
:
typedef QList<HistoryItem*> HistoryList_t;
...
qRegisterMetaType<HistoryList_t>("HistoryList_t");
Then use this type in your signals and slots:
public slots:
void historyLoaded(const HistoryList_t &list);
Upvotes: 3
Reputation: 13238
Check return value of your connect
, it should fail. There is an extra *
in SIGNAL(historyLoaded(QList<HistoryItem*>*))
, should be SIGNAL(historyLoaded(QList<HistoryItem*>))
. Fix your SLOT()
too.
Upvotes: 1