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. Beginner question on signals and slots.
QtWS25 Last Chance

Beginner question on signals and slots.

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 692 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.
  • mstothM Offline
    mstothM Offline
    mstoth
    wrote on last edited by
    #1

    I have been searching but can not seem to find the answer to this simple question.

    How do you connect a slot in a dialog to a signal from a different dialog when they are instantiated from different places?

    I have a dialog A which creates a dialog B. This dialog B then creates dialog C. All three are instances of different classes.

    I want to connect a signal from C to a slot in A but when I create C from B, C knows nothing of A and when I create B from A, A knows nothing of C.
    I don't want to use globals. I feel there must be a simple way to do this but I'm just not getting it yet.

    so in A, I can't do connect(C, SIGNAL(s1()), this, SLOT(s1())) because I don't have the C dialog created yet,
    and in C, I can't do connect(this, SIGNAL(s1()), A, SLOT(s1())) because C doesn't have a pointer to A.

    Thanks for any help!
    -Michael

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2
      1. define in signal in B
      2. Connect signal in C in to Signal in B(make signal to signal)
      3. Connect signal in B to Slot in A

      SignalC->SignalB->SlotA

      In general objects should be available to connect. You can make chain of signal/slots like the one explained above.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      7
      • mstothM Offline
        mstothM Offline
        mstoth
        wrote on last edited by mstoth
        #3

        Thanks. I didn't think of chaining the signals and slots. One solution I did find was to do a search for all open widgets in the application and select the one that matches the intended destination. This works but perhaps chaining the signals and slots would be more elegant.
        Is the chaining approach considered the best practice generally?
        Thanks again.

        A 1 Reply Last reply
        0
        • mstothM mstoth

          Thanks. I didn't think of chaining the signals and slots. One solution I did find was to do a search for all open widgets in the application and select the one that matches the intended destination. This works but perhaps chaining the signals and slots would be more elegant.
          Is the chaining approach considered the best practice generally?
          Thanks again.

          A Offline
          A Offline
          ambershark
          wrote on last edited by
          #4

          @mstoth Yea typically chaining is how you would do that. That's how I've always done it.

          The lazier way is to pass a pointer from dialog A down to dialog C so you can use it for your signals/slots. That method of course creates an interdependence that you typically don't want in your code though. :)

          My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

          1 Reply Last reply
          1
          • H Offline
            H Offline
            HafsaElif
            wrote on last edited by HafsaElif
            #5
            This post is deleted!
            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