我在假定的SLOT
中无法接收到我的自定义信号。这里是我的代码:未收到Qt发出的信号
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()...";
}
而且这是我发出信号:
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() << "historyLoaded()...";
。
任何想法可能是什么问题?
退房http://stackoverflow.com/:
然后在你的信号和槽使用这种类型question/26422154/my-slot-is-not-invoked-called-used-working-executed – Silicomancer 2014-12-02 12:20:55
您确定信号/插槽机制可以处理模板吗? http://qt-project.org/doc/qt-4.8/templates.html – vahancho 2014-12-02 12:25:22
如果你在Qt5或以上,你可以使用'connect(dbtrad,&dbThread :: historyLoaded,this,&MainWindow :: historyLoaded);' – 2014-12-02 12:44:57