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. is it possible to pass a argument from signal to slot?
Forum Updated to NodeBB v4.3 + New Features

is it possible to pass a argument from signal to slot?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.4k Views 1 Watching
  • 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.
  • Q Offline
    Q Offline
    qtpi
    wrote on last edited by
    #1

    like
    connect(this, SIGNAL(signal(int b)), this, SLOT(slot(int b)));

    slot(int b)
    { std::cout<<b<<std::endl; }

    I know there is a QSignalMapper, but it seems it's not gonna work if I want to pass a random argument, I have to set all the maps which could come up.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You connection statement is wrong, remove b from it, only the type should be passed.

      What do you mean by "pass random argument" ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Q 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        You connection statement is wrong, remove b from it, only the type should be passed.

        What do you mean by "pass random argument" ?

        Q Offline
        Q Offline
        qtpi
        wrote on last edited by
        #3

        @SGaist hi, I mean if I do it with QSignalMapper, I can only pass the argument that are already set by the mapper.

        So basically my question is if it's possible to pass arguments from signal to a slot directly.

        I checked some sources and it seems it cannot be done this way.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What you are asking is not really clear. Can you show an example of what you want to achieve exactly ? With what you expect to get.

          Because currently you seem to describe the standard signal and slot behavior. Meaning that if you take your original post sample code, calling for example emit signal(5) will give you 5\n on stdout.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          Q 1 Reply Last reply
          0
          • SGaistS SGaist

            What you are asking is not really clear. Can you show an example of what you want to achieve exactly ? With what you expect to get.

            Because currently you seem to describe the standard signal and slot behavior. Meaning that if you take your original post sample code, calling for example emit signal(5) will give you 5\n on stdout.

            Q Offline
            Q Offline
            qtpi
            wrote on last edited by
            #5

            @SGaist

            object1.cpp
            int a = func();
            connect(Object1, SIGNAL(signal(a)), Object2, SLOT(slot(a)));

            object2.cpp
            slot(a)
            {
            //something happened with a as argument
            }

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              No, that's not how it's working.

              See the Signals and Slots chapter of Qt's documentation.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              • Login

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