Results 1 to 4 of 4

Thread: Signals and Slots woes

  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Signals and Slots woes

    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:

    Qt Code:
    1. public slots:
    2. void setSingleModeEdit();
    3. void setSingleModeEntry();
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void ControlDB::setSingleModeEdit() {
    2. qDebug() << "single display mode changed to EDIT";
    3. QSqlDatabase db = QSqlDatabase::database(ctrlConn);
    4. QSqlQuery query(db);
    5. query.prepare("UPDATE preferences set defaultSingleView = ?");
    6. query.addBindValue("EDIT");
    7. query.exec();
    8. }
    9.  
    10. void ControlDB::setSingleModeEntry() {
    11. qDebug() << "single display mode changed to ENTRY";
    12. QSqlDatabase db = QSqlDatabase::database(ctrlConn);
    13. QSqlQuery query(db);
    14. query.prepare("UPDATE preferences set defaultSingleView = ?");
    15. query.addBindValue("ENTRY");
    16. query.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 

    Here is the code in EnterLog:

    Qt Code:
    1. ControlDB ctrl;
    2. connect(ui->rbEdit, SIGNAL(clicked()), &ctrl, SLOT(setSingleModeEdit()));
    3. connect(ui->rbEntry, SIGNAL(clicked()), &ctrl, SLOT(setSingleModeEntry()));
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Signals and Slots woes

    You should check that ctrl reference is still valid when the signals are emitted.

  3. The following 2 users say thank you to Zlatomir for this useful post:

    waynew (14th May 2010), zoz (4th June 2010)

  4. #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: Signals and Slots woes

    Your ctrl object goes out of scope and is destroyed before anything has a chance to happen.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following 2 users say thank you to wysota for this useful post:

    waynew (14th May 2010), Zlatomir (14th May 2010)

  6. #4
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signals and Slots woes

    Thanks folks. Working fine now.

Similar Threads

  1. More SQLite Woes and onFocus Woes
    By morraine in forum Newbie
    Replies: 1
    Last Post: 13th August 2008, 13:14
  2. about signals and slots
    By Sandip in forum Qt Programming
    Replies: 9
    Last Post: 15th July 2008, 16:02
  3. Signals and slots
    By sylvarant in forum Newbie
    Replies: 4
    Last Post: 11th September 2007, 15:48
  4. Signals and Slots
    By merry in forum Qt Programming
    Replies: 4
    Last Post: 22nd February 2007, 08:11
  5. Signals and Slots in dll
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 29th March 2006, 08:12

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.