Using singals and slots in an efficient way

  • In my qt c++ application I have 4 interfaces! The first interface takes a value through a line edit and I want to send it to the last interface(4th interface) file(CPP file). Currently I send it using signals and slots through interface 2 and 3 to the 4th interface! Is there any way to send the variable value taken from line edit directly from 1st interface file to the 4th interface file?

  • @Lasith
    I assume you're using a signal forwarding (signal to signal connection).

    It not that costly as you think, especially with implicitly shared container (QString in your case).

    From documentation:
    it's much less overhead than any new or delete operation, for example. As soon as you perform a string, vector or list operation that behind the scene requires new or delete, the signals and slots overhead is only responsible for a very small proportion of the complete function call costs

    Also, if you can get a pointer to 4th interface from your 1st, you can make a connection without signal forwarding.

  • @dream_captain You mean if we have 10 interfaces inorder to send a value from 1st interface to the 10th interface we have to create signal slot pairs in each interface? :O

  • @Lasith
    No, in this case use QSignalMapper.