PDA

View Full Version : Signals and Slots woes



waynew
13th May 2010, 23:37
Trying to connect a pair of mutually exclusive radio buttons to slots in a different class.
Signals originate from class EnterLog when a radio button is clicked and should be received in ControlDB. The slot functions are defined as public slots in ControlDB.
Here is the code in ControlDB:



public slots:
void setSingleModeEdit();
void setSingleModeEntry();




void ControlDB::setSingleModeEdit() {
qDebug() << "single display mode changed to EDIT";
QSqlDatabase db = QSqlDatabase::database(ctrlConn);
QSqlQuery query(db);
query.prepare("UPDATE preferences set defaultSingleView = ?");
query.addBindValue("EDIT");
query.exec();
}

void ControlDB::setSingleModeEntry() {
qDebug() << "single display mode changed to ENTRY";
QSqlDatabase db = QSqlDatabase::database(ctrlConn);
QSqlQuery query(db);
query.prepare("UPDATE preferences set defaultSingleView = ?");
query.addBindValue("ENTRY");
query.exec();
}


Here is the code in EnterLog:



ControlDB ctrl;
connect(ui->rbEdit, SIGNAL(clicked()), &ctrl, SLOT(setSingleModeEdit()));
connect(ui->rbEntry, SIGNAL(clicked()), &ctrl, SLOT(setSingleModeEntry()));


The problem is, the signals don't get received. What am I doing wrong here?

Zlatomir
13th May 2010, 23:50
You should check that ctrl reference is still valid when the signals are emitted.

wysota
14th May 2010, 00:25
Your ctrl object goes out of scope and is destroyed before anything has a chance to happen.

waynew
14th May 2010, 01:02
Thanks folks. Working fine now.