How to ensure handling of signals before executing next statement?



  • I have a sender that emits a signal toDelete(ObjectOfMyClass*). The next statement after this signal will be deletion of the ObjectOfMyClass. How do I ensure that any receivers of this signal execute their slot code before the deletion of the ObjectOfMyClass? Point is that these receivers need to access ObjectOfMyClass before it is actually deleted?


  • Qt Champions 2016

    Hi
    If you use DirectConnection
    connect( A, SIGNAL(somethingChanged()), B, SLOT(handleChange()), Qt::DirectConnection );
    Then its much like a function call but i never tested if you can rely on it :)



  • Well, I have used it, but found a way where I don't need to rely so much on it anymore. So, solved in two ways at the same time :lol:


  • Qt Champions 2016

    Well, a better/other design where it is not need to say goodbye to an instance would be prefered.
    So sounds like you found the truly right solution :)



  • Well, I needed it for another occasion and there Qt::DirectConnection seems to work to satisfaction :)


  • Lifetime Qt Champion

    Hi,

    Until you start having threads in the mix.

    The design looks a bit dubious, you should rather have some sort of synchronisation mechanism.

    What does the connected objects have to do with your ObjectOfMyClass instance when it's about to get destroyed ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.