Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to create a QT signal dynamically?
Forum Update on Monday, May 27th 2025

How to create a QT signal dynamically?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Savitha
    wrote on 4 Jul 2022, 04:44 last edited by
    #1

    Hi All,

    I have a need to create QT signals dynamically in a for loop and will store in a map. I was told to make use of std::bind() method but bind method can be used for already existing functions. So how can I create the new functions and what is the correct method?

    I am expecting something like below:

    std::map<quint8, std::functionstd::string(std::string)> m_newSignals;

    In my constructor I need:
    for (quint8 loc_var=0; loc_var < final_value; loc_var++)
    {
    m_newSignals[loc_var] = std::bind(); //should generate new function
    }

    In a different function I need to emit the new signals created as:
    for (quint8 loc_var=0; loc_var < final_value; loc_var++)
    {
    l_functionToCall = m_newSignals.at(loc_var);
    emit l_functionToCall(put parameters);
    }

    Can someone help with this?

    J 1 Reply Last reply 4 Jul 2022, 05:25
    0
    • S Savitha
      4 Jul 2022, 04:44

      Hi All,

      I have a need to create QT signals dynamically in a for loop and will store in a map. I was told to make use of std::bind() method but bind method can be used for already existing functions. So how can I create the new functions and what is the correct method?

      I am expecting something like below:

      std::map<quint8, std::functionstd::string(std::string)> m_newSignals;

      In my constructor I need:
      for (quint8 loc_var=0; loc_var < final_value; loc_var++)
      {
      m_newSignals[loc_var] = std::bind(); //should generate new function
      }

      In a different function I need to emit the new signals created as:
      for (quint8 loc_var=0; loc_var < final_value; loc_var++)
      {
      l_functionToCall = m_newSignals.at(loc_var);
      emit l_functionToCall(put parameters);
      }

      Can someone help with this?

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 4 Jul 2022, 05:25 last edited by
      #2

      @Savitha you can't create Signals dynamically.

      Every single one of them has to be declared at compile time, and as an additionally limitation by MOC, templates do also not work.

      The closed thing you can do is store your signals in an array and access them later on that way, see here for an example that I made

      https://forum.qt.io/topic/128026/is-it-possible-to-mimic-the-functionality-of-an-array-of-signals/12


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      S 1 Reply Last reply 4 Jul 2022, 05:30
      1
      • J J.Hilk
        4 Jul 2022, 05:25

        @Savitha you can't create Signals dynamically.

        Every single one of them has to be declared at compile time, and as an additionally limitation by MOC, templates do also not work.

        The closed thing you can do is store your signals in an array and access them later on that way, see here for an example that I made

        https://forum.qt.io/topic/128026/is-it-possible-to-mimic-the-functionality-of-an-array-of-signals/12

        S Offline
        S Offline
        Savitha
        wrote on 4 Jul 2022, 05:30 last edited by
        #3

        @J-Hilk Thanks for the reply, I will check your sample code

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Kent-Dorfman
          wrote on 5 Jul 2022, 01:07 last edited by
          #4

          There shouldn't be a need for dynamic signals since the signal/slot mechanism allows parameter passing. a single parametized signal allows the receiving slot to understand the context in which the signal was sent.

          1 Reply Last reply
          1

          1/4

          4 Jul 2022, 04:44

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved