Just when I thought I had signals and slots figured out ... not so.
I have one class (editlog) that sends a signal to a slot in the mainwindow, and it works fine.
So I set up another one from a different class (openlog), and ... nothing, no response.
Here is the code that works ok:
// part of editlog.h
signals:
void addLookup(int);
// part of editlog.cpp
void EditLog::on_pushButton_clicked()
{
emit addLookup(::logID);
}
// part of mainwindow.h
public:
EditLog *el;
public slots:
void updateLog(int);
// part of mainwindow.cpp
el = new EditLog;
// Signal connection from EditLog class
connect(el, SIGNAL(addLookup(int)), this, SLOT(updateLog(int)));
void MainWindow::updateLog(int newID)
{
// code updates log ok
}
// part of editlog.h
signals:
void addLookup(int);
// part of editlog.cpp
void EditLog::on_pushButton_clicked()
{
emit addLookup(::logID);
}
// part of mainwindow.h
public:
EditLog *el;
public slots:
void updateLog(int);
// part of mainwindow.cpp
el = new EditLog;
// Signal connection from EditLog class
connect(el, SIGNAL(addLookup(int)), this, SLOT(updateLog(int)));
void MainWindow::updateLog(int newID)
{
// code updates log ok
}
To copy to clipboard, switch view to plain text mode
Here is the code that seems to do nothing:
// part of openlog.h // this is a dialog
signals:
// part of openlog.cpp
void OpenLog::on_pbOpen_clicked()
{
QString openLog
= ui
->cbLogName
->currentText
();
emit callOpenLog(openLog);
close(); // the dialog window
}
// part of mainwindow.h
public:
OpenLog *ol;
// part of mainwindow.cpp
ol = new OpenLog;
connect(ol,
SIGNAL(callOpenLog
(QString)),
this,
SLOT(openLog
(QString)));
void MainWindow
::openLog(QString logName
) // never called {
// code would open the log if the signal was received
}
// part of openlog.h // this is a dialog
signals:
void callOpenLog(QString);
// part of openlog.cpp
void OpenLog::on_pbOpen_clicked()
{
QString openLog = ui->cbLogName->currentText();
emit callOpenLog(openLog);
close(); // the dialog window
}
// part of mainwindow.h
public:
OpenLog *ol;
// part of mainwindow.cpp
ol = new OpenLog;
connect(ol, SIGNAL(callOpenLog(QString)), this, SLOT(openLog(QString)));
void MainWindow::openLog(QString logName) // never called
{
// code would open the log if the signal was received
}
To copy to clipboard, switch view to plain text mode
Could this have something to do with the fact that the signal from the class that works comes from a dialog window that does not get closed after the signal is sent and the one that does not work comes from a dialog class where the window gets closed right after the signal is sent. If so, how to make it work? Or what else is wrong?
Bookmarks