Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 未接收到Qt发出的信号_C++_Qt - Fatal编程技术网

C++ 未接收到Qt发出的信号

C++ 未接收到Qt发出的信号,c++,qt,C++,Qt,我无法在假定的插槽中接收自定义信号。这是我的密码: mainwindow.h: 这就是我发出信号的方式: QList<HistoryItem*> innerResult; while (queryInner.next()) { QString channelIDInner = queryInner.value(0).toString(); HistoryItem* item = new HistoryItem(); item->channel = ch

我无法在假定的插槽中接收自定义信号。这是我的密码:

mainwindow.h:

这就是我发出信号的方式:

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);

然而,qDebug检查连接的返回值,它应该失败。SIGNALhistoryLoadedQList*中有一个额外的*应该是SIGNALhistoryLoadedQList。也修复你的插槽。

看起来你在使用线程。在跨线程发送信号时使用QList,或者通常使用Qt::QueuedConnection需要一些额外的工作。基本上,您需要使用typedef定义QList类型,然后使用qRegisterMetaType注册它:


检查您是否确定信号/插槽机制可以处理模板?如果您在Qt5或更高版本,则可以使用connectdbtrad、&dbThread::historyLoaded、this、&MainWindow::historyLoaded;更改为connectdbtrad,SIGNALhistoryLoadedQList,this,SLOThistoryLoadedQList;但您的插槽仍然是historyLoadedconst QList。从插槽中删除常量或将其添加到信号。并检查您的连接返回的内容,直到它返回真值,您的插槽将不会被触发。
connect(dbtrad, SIGNAL(historyLoaded(QList<HistoryItem*>*)), this, SLOT(historyLoaded(QList<HistoryItem*>*)));

void MainWindow::historyLoaded(QList<HistoryItem*> innerResult) {
    qDebug() << "historyLoaded()...";
}
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);
typedef QList<HistoryItem*> HistoryList_t;
...
qRegisterMetaType<HistoryList_t>("HistoryList_t");
public slots:
    void historyLoaded(const HistoryList_t &list);