PDA

View Full Version : Slot doesn't get called



waynew
17th April 2010, 22:58
This should be simple, but I don't see it.
Trying to emit a signal in the EditLog class to call a slot in the MainWindow.
No error, but the slot doesn't get called.

the EditLog.h entries:


signals:
void logChanged();

private slots:
void on_pbSave_clicked();
void on_pbCancel_clicked();


the EditLog cpp


void EditLog::on_pbSave_clicked()
{
// some code
emit logChanged();


the MainWindow.h


public slots:
void updateLogView();


the MainWindow.cpp // updateLogView never gets executed


// in the constructor:
EditLog el;
connect(&el, SIGNAL(logChanged()), this, SLOT(updateLogView()));
//
void MainWindow::updateLogView() {
view->selectionModel()->clearSelection();
model->select();
view->resizeColumnsToContents();
qDebug() << "edit model error is " << model->lastError();
}


Any idea what I am missing?

squidge
18th April 2010, 00:27
What does the output window say?

waynew
18th April 2010, 01:16
I have a debug after the emit and it displays ok. The edit model debug message does not display.
So that and the fact that the view does not show the changed data lead me to believe that the updateLogView function is not being called.
Thanks for responding Mole - do you see anything I am doing wrong or have left out? Something is definitely not right.

norobro
18th April 2010, 01:21
Hi Waynew,

Try creating your EditLog on the heap.

waynew
18th April 2010, 01:27
Ok, I tried this:


EditLog *el = new EditLog;
connect(el, SIGNAL(logChanged()), this, SLOT(updateLogView()));


Same results.

norobro
18th April 2010, 01:55
The code you've posted looks okay to me. I created a project that is a crude approximation of what you are doing and got no errors but the slot is not called if created on the stack. Works fine created on the heap.

waynew
18th April 2010, 02:26
Thanks for going to all of that trouble Norobro. I'll check it out and see what I can figure out. Will post later.

waynew
18th April 2010, 13:34
Ok, working now thanks to your help. I believe the problem I had was 2 instantiations of EditLog. One for the signal and one where I had to call the edit function. Fixed that and it gets the signal fine now.