Results 1 to 9 of 9

Thread: Signal Slot not working

  1. #1
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Signal Slot not working

    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.

    Qt Code:
    1. TextFileImporter *importer = new TextFileImporter(cDetails,(QWidget *)parent());
    2. connect(importer,SIGNAL(importDone()),this,SIGNAL(importDone()));
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. Import importer(contactDetails,this);
    2. connect(&importer,SIGNAL(importDone()),this,SLOT(importDone()));
    To copy to clipboard, switch view to plain text mode 

    THE SLOT

    Qt Code:
    1. void AppWindow::importDone()
    2. {
    3. //This slot is never called
    4. }
    To copy to clipboard, switch view to plain text mode 

    The place where signal is emitted

    Qt Code:
    1. void TextFileImporter::importAll()
    2. {
    3. qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
    4. hide();
    5.  
    6. dataTable->blockSignals(true);
    7.  
    8. //import code here
    9.  
    10. emit importDone();
    11.  
    12. dataTable->blockSignals(false);
    13.  
    14. show();
    15.  
    16. qApp->restoreOverrideCursor();
    17. }
    To copy to clipboard, switch view to plain text mode 

    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

    Qt Code:
    1. // SIGNAL 0
    2. void Import::importDone()
    3. {
    4. QMetaObject::activate(this, &staticMetaObject, 0, 0);
    5. }
    To copy to clipboard, switch view to plain text mode 

    moc_textfileimporter.cpp

    Qt Code:
    1. // SIGNAL 0
    2. void TextFileImporter::importDone()
    3. {
    4. QMetaObject::activate(this, &staticMetaObject, 0, 0);
    5. }
    To copy to clipboard, switch view to plain text mode 

    moc_appwindow.cpp

    Qt Code:
    1. int AppWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
    2. {
    3. _id = QMainWindow::qt_metacall(_c, _id, _a);
    4. if (_id < 0)
    5. return _id;
    6. if (_c == QMetaObject::InvokeMetaMethod) {
    7. switch (_id) {
    8. case 0:
    9. ....
    10. ....
    11. case 65: importDone(); break;
    12. }
    13. _id -= 66;
    14. }
    15. return _id;
    16. }
    To copy to clipboard, switch view to plain text mode 

    Can someone please tell me what's wrong?

    Thanks a lot!

  2. #2
    Join Date
    Sep 2006
    Posts
    8
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Signal Slot not working

    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

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Signal Slot not working

    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?

  4. #4
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Signal Slot not working

    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!

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Signal Slot not working

    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.

  6. #6
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Signal Slot not working

    Quote Originally Posted by wysota
    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.

    Quote Originally Posted by wysota
    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.

    Quote Originally Posted by wysota
    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.

    Quote Originally Posted by wysota
    You might want to try a singal spy to check that out.
    How can I get a signal spy ?

  7. #7
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Signal Slot not working

    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!

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Signal Slot not working

    Quote Originally Posted by munna View Post
    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.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Signal Slot not working

    Quote Originally Posted by munna View Post
    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.

Similar Threads

  1. signal slot connection
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 4th July 2006, 13:31
  2. Replies: 1
    Last Post: 11th June 2006, 22:25
  3. signal not getting communicated to slot
    By quickNitin in forum Qt Programming
    Replies: 17
    Last Post: 2nd June 2006, 04:56
  4. Manually send signal to slot
    By donmorr in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2006, 15:03
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.