Important: Please read the Qt Code of Conduct -

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?

  • Lifetime Qt Champion

    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:

  • Lifetime Qt Champion

    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


    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