2

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?

BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
Alosyius
  • 8,771
  • 26
  • 76
  • 120

2 Answers2

3

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);
thuga
  • 12,601
  • 42
  • 52
1

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.

Paul
  • 13,042
  • 3
  • 41
  • 59
  • changed to `connect(dbtrad, SIGNAL(historyLoaded(QList)), this, SLOT(historyLoaded(QList)));` but still same – Alosyius Dec 02 '14 at 12:21
  • Your slot is `historyLoaded(const QList)`. Either remove `const` from slot or add it to signal. And check what your `connect` returns, until it returns `true` your slot won't be triggered. – Paul Dec 02 '14 at 12:37