Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6996071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:06:35+00:00 2026-05-27T20:06:35+00:00

I have an Object X which owns (owns pointers to and initializes) Objects Y1..10

  • 0

I have an Object X which owns (owns pointers to and initializes) Objects Y1..10

Object X has a state that changes from time to time.
I’d like the child objects (Y1..10) to become aware of the state.

Typically, this is resolvable by having a pointer to the parent X from each Y child object, so that it can query its status via a method call, but I don’t want the Y objects to be aware of object X, just its status.

I was wondering if this could be implemented with signals/slots:

The Y objects will define a signal such as:

void GetStatus(TheStatus & status);

The X object will connect this to a slot, and when emitted by a Y object, object X will write the status onto the status reference given so that the Y object gets it.

This way I can have status updates be available for Y objects, and yet, they do not need to be aware of object X to achieve that.

What do you think?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:06:36+00:00Added an answer on May 27, 2026 at 8:06 pm

    It looks like you are thinking of it backwards. If the X object is the one that wants to do the “notifying”, then it should be emitting the signal. Then the Y objects would have the slot to be the “receivers”.

    So X object should be emitting a signal, like:

    void X::statusChanged(TheStatus status);
    

    Then the Y object would have some kind of matching slot. Assuming proper private/public privileges, any object—perhaps Z or even X and Y themselves—could use the QObject::connect call to tie together matching signals and slots of object instances together. You can even tie signals to signals.

    While it’s possible that you could call that slot in Y something like onStatusChanged, that suggests a little too tight a coupling in your design. After all, a slot can be called just like a regular method. So if you can think of what the slot actually does rather than naming it on the basis of its caller, that can be more sensible.

    (If a function foo() calls another function, we tend to give that a new name bar() based on what it does, instead of theFunctionCalledByFoo(), right?)

    It’s preferable as Martin pointed out to try and keep the types that slots use fairly basic and send them by value. If you send pointers and references then you get into worries about object lifetimes, especially in multithreaded scenarios where the signals/slots are processed in a queue.

    A good example of a notification-based class to play with that’s simple to understand might be the progress bar:

    http://developer.qt.nokia.com/doc/qt-4.8/qprogressbar.html#details

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object which has several properties that are set when the object
I have an object which has a state property, for example state = 'state4'
I have object A which in turn has a property of type Object B
So I have an object which has some fields, doesn't really matter what. I
In the ADO.Net Entity Framework, I have an object which has 4 references to
I have an object which is derived from DependencyObject with multiple DependencyProperties. This object
I have an object which owns a property Texture_ID. I need to initialize the
I have an object which looks for example like this Name Number ---- ------
I have two complicated PHP objects, each of which has data in a few
I have an object which has a property of type ObservableCollection<bool> . It is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.