PDA

View Full Version : Signal Slot not working



munna
6th November 2006, 09:54
Hi,

I have connected and signal to another signal and it to a slot.

Here is how I am using it but the slot is never called.




TextFileImporter *importer = new TextFileImporter(cDetails,(QWidget *)parent());
connect(importer,SIGNAL(importDone()),this,SIGNAL( importDone()));






Import importer(contactDetails,this);
connect(&importer,SIGNAL(importDone()),this,SLOT(importDone ()));



THE SLOT




void AppWindow::importDone()
{
//This slot is never called
}



The place where signal is emitted




void TextFileImporter::importAll()
{
qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
hide();

dataTable->blockSignals(true);

//import code here

emit importDone();

dataTable->blockSignals(false);

show();

qApp->restoreOverrideCursor();
}



I have no idea why the slot is not called. I tried looking into the moc file and here is what I found

moc_import.cpp




// SIGNAL 0
void Import::importDone()
{
QMetaObject::activate(this, &staticMetaObject, 0, 0);
}



moc_textfileimporter.cpp




// SIGNAL 0
void TextFileImporter::importDone()
{
QMetaObject::activate(this, &staticMetaObject, 0, 0);
}



moc_appwindow.cpp




int AppWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QMainWindow::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
switch (_id) {
case 0:
....
....
case 65: importDone(); break;
}
_id -= 66;
}
return _id;
}



Can someone please tell me what's wrong?

Thanks a lot!

hubert_p
6th November 2006, 10:11
Are you sure that you place your connect in the good classes.

Do not look what the moc generate. This is automatically regenarate and that work fine.

Philippe

wysota
6th November 2006, 10:17
Maybe the reason is that you create the second object on the stack and it gets destroyed when the function ends? And in the first connect - is the connection between two signals on purpose? Or should the second argument be a slot?

munna
6th November 2006, 10:19
There are atleast 60 other slots in the same class that are working fine. I am not able to figure out the mistake.

Please help
Thanks a lot!

wysota
6th November 2006, 10:20
What if you connect the same slot to a different signal or connect a different slot to this signal? Does the signal get emitted at all? You might want to try a singal spy to check that out.

munna
6th November 2006, 10:32
Maybe the reason is that you create the second object on the stack and it gets destroyed when the function ends?

No, the signal is emitted before the function ends.


And in the first connect - is the connection between two signals on purpose? Or should the second argument be a slot?

Yes it is connected to a signal on purpose. The flow is something like

AppWindow creates Import object. The import object creates TextFileImport Object.

TextFileImport object emits importDone() which is connected to the signal importDone() of Import Object. This signal is inturn connected to the slot importDone of AppWindow object.


What if you connect the same slot to a different signal or connect a different slot to this signal? Does the signal get emitted at all?

Let me try this.


You might want to try a singal spy to check that out.

How can I get a signal spy ?

munna
6th November 2006, 10:34
I tried connecting to another slot, but the slot is not called. This means, the signal is never emitted. What should I do?

Thanks a lot!

wysota
6th November 2006, 10:34
How can I get a signal spy ?

Two implementations are available. One from Trolltech (available in QtTestLib module AFAIR) and the other by (I think) Johan Thelin - it should be available for download on his site.

wysota
6th November 2006, 10:36
I tried connecting to another slot, but the slot is not called. This means, the signal is never emitted. What should I do?!

Trace where does the signal get lost. It might be lost during forwarding or the original signal might not be emitted at all. Either use a ready-made signal spy or create your own and attach it to all the signals and display messages whenever each signal gets emitted.