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

  • SEARCH
  • Home
  • 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 122169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:05:10+00:00 2026-05-11T04:05:10+00:00

I have a program that (amongst other things) has a command line interface that

  • 0

I have a program that (amongst other things) has a command line interface that lets the user enter strings, which will then be sent over the network. The problem is that I’m not sure how to connect the events, which are generated deep inside the GUI, to the network interface. Suppose for instance that my GUI class hierarchy looks like this:

GUI -> MainWindow -> CommandLineInterface -> EntryField

Each GUI object holds some other GUI objects and everything is private. Now the entryField object generates an event/signal that a message has been entered. At the moment I’m passing the signal up the class hierarchy so the CLI class would look something like this:

public:     sig::csignal<void, string> msgEntered; 

And in the c’tor:

entryField.msgEntered.connect(sigc::mem_fun(this, &CLI::passUp)); 

The passUp function just emits the signal again for the owning class (MainWindow) to connect to until I can finally do this in the main loop:

gui.msgEntered.connect(sigc::mem_fun(networkInterface, &NetworkInterface::sendMSG)); 

Now this seems like a real bad solution. Every time I add something to the GUI I have to wire it up all through the class hierarchy. I do see several ways around this. I could make all objects public, which would allow me to just do this in the main loop:

gui.mainWindow.cli.entryField.msgEntered.connect(sigc::mem_fun(networkInterface, &NetworkInterface::sendMSG)); 

But that would go against the idea of encapsulation. I could also pass a reference to the network interface all over the GUI, but I would like to keep the GUI code as seperate as possible.

It feels like I’m missing something essential here. Is there a clean way to do this?

Note: I’m using GTK+/gtkmm/LibSigC++, but I’m not tagging it as such because I’ve had pretty much the same problem with Qt. It’s really a general question.

  • 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. 2026-05-11T04:05:11+00:00Added an answer on May 11, 2026 at 4:05 am

    Short of having some global pub/sub hub, you aren’t going to get away from passing something up or down the hierarchy. Even if you abstract the listener to a generic interface or a controller, you still have to attach the controller to the UI event somehow.

    With a pub/sub hub you add another layer of indirection, but there’s still a duplication – the entryField still says ‘publish message ready event’ and the listener/controller/network interface says ‘listen for message ready event’, so there’s a common event ID that both sides need to know about, and if you’re not going to hard-code that in two places then it needs to be passed into both files (though as global it’s not passed as an argument; which in itself isn’t any great advantage).

    I’ve used all four approaches – direct coupling, controller, listener and pub-sub – and in each successor you loosen the coupling a bit, but you don’t ever get away from having some duplication, even if it’s only the id of the published event.

    It really comes down to variance. If you find you need to switch to a different implementation of the interface, then abstracting the concrete interface as a controller is worthwhile. If you find you need to have other logic observing the state, change it to an observer. If you need to decouple it between processes, or want to plug into a more general architecture, pub/sub can work, but it introduces a form of global state, and isn’t as amenable to compile-time checking.

    But if you don’t need to vary the parts of the system independently it’s probably not worth worrying about.

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

Sidebar

Ask A Question

Stats

  • Questions 88k
  • Answers 88k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you are using VB.NET you are not using VB6… May 11, 2026 at 5:40 pm
  • Editorial Team
    Editorial Team added an answer You can do the same thing in C, but you… May 11, 2026 at 5:40 pm
  • Editorial Team
    Editorial Team added an answer EDIT BASED ON THE ASKERS FEEDBACK: I didn't realize you… May 11, 2026 at 5:40 pm

Related Questions

I am trying to come to grips with how difficult it is to use
I have a program that spits out both standard error and standard out, and
I have a program that creates a Windows user account using the NetUserAdd() API
I have a program that uses the mt19937 random number generator from boost::random. I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.