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. Wrapping brain around SIGNALS

Wrapping brain around SIGNALS

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.1k 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.
  • R Offline
    R Offline
    ronM71
    wrote on last edited by
    #1

    I have a class A with signal sendRequest(somepayload * payload)
    I have a class B with slot OnRequest(somepayload * payload)

    I connect the two with QObject::connect..

    In class B i implement a slot for "somepayload".

    But in class A, what do I do? other methods in A call "emit(this->somepayload(payload))" but all I really want is for "OnRequest" to be called in class B with my payload.

    What do I implement in class A? It seems I have to "implement" the signal, but what exactly should I do there? it doesn't make sense. Can I leave it empty?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Nothing to do. You must not implement a signal yourself. Just declare it in the header file under the signals keyword.

      Behind the scenes, it is a regular C++ method, but the actual implementation is provided by Qt (this is one of the points where moc enters the game).

      Just call "emit sendRequest(myPayload)", that's all.

      If your class A knows of class B, and if you have a B object, you can call B's slot directly too. Your two classes are then coupled tightly.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • R Offline
        R Offline
        ronM71
        wrote on last edited by
        #3

        got you. thanks what I did in the end. Just wanted to make sure I wasn't missing anything.

        1 Reply Last reply
        0

        • Login

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