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 929623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:12:09+00:00 2026-05-15T20:12:09+00:00

I have some constructor for the class LCDRange: LCDRange::LCDRange(QWidget *parent) : QWidget(parent) { QLCDNumber

  • 0

I have some constructor for the class LCDRange:

 LCDRange::LCDRange(QWidget *parent)
     : QWidget(parent)
 {
     QLCDNumber *lcd = new QLCDNumber(2);
     lcd->setSegmentStyle(QLCDNumber::Filled);

     slider = new QSlider(Qt::Horizontal);
     slider->setRange(0, 99);
     slider->setValue(0);

     connect(slider, SIGNAL(valueChanged(int)),
             lcd, SLOT(display(int)));
     connect(slider, SIGNAL(valueChanged(int)),
             this, SIGNAL(valueChanged(int)));

     QVBoxLayout *layout = new QVBoxLayout;
     layout->addWidget(lcd);
     layout->addWidget(slider);
     setLayout(layout);
 }

but I can’t understand the difference between these lines:

connect(slider, SIGNAL(valueChanged(int)),
                 lcd, SLOT(display(int)));
connect(slider, SIGNAL(valueChanged(int)),
                 this, SIGNAL(valueChanged(int)));

thanks in advance

  • 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-15T20:12:09+00:00Added an answer on May 15, 2026 at 8:12 pm

    Remember that we are in OO land, so we are operating on objects.

    In order to connect a signal to something, those signal/slots have to be apart of an object.

    Another way to think about it is you can’t have a signal by itself, because a signal has to come from somewhere. Likewise, you can’t have a slot all by itself it has to be attached to something.

    Now, Qt allows you to connect a signal to a slot, but it also allows you to connect a signal to a signal, which is what is happening in the second connect line. This allows you to chain signals from one object to another, or you could think about it as passing a signal through.

    Usually this happens when an Object or Widget has a private internal child that emits a signal, and the parent Object/Widget wants to emit the same signal to whoever is listening to it.

    In the case of your example the LCDRange Widget contains a slider, which is an internal implementation detail. The user of LCDRange doesn’t need to know about all the different components that make up the LCDRange (slider, lcdnumber, layout, etc), that’s a basic requirement of encapsulation which is a huge advantage of OO.

    However, the user of LCDRange will want to know when the value of LCDRange changes. And rather then creating a slot in LCDRange, that simply re-emits the signal valueChanged signal, you can forward or passthrough the valueChanged signal from the slider.

    The following achieves the same effect of passing the signal through, however it requires much more code.

    class LCDRange : public QWidget
    {
    // constructor and other methods
    //...
    signals:
        void valueChanged(int)
    private slots:
        void sliderValueChanged(int);
    // ...
    };
    
    // in the LCDRange constructor
    connect(slider, SIGNAL(valueChanged(int)),
                     this, SLOT(sliderValueChanged(int)));
    
    // elsewhere in LCDRange's definition
    
    void LCDRange::sliderValueChanged( int value )
    {
        emit valueChanged( value );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a Java class where I have defined a constructor and some
I have some class( Window ) without copy constructor (it's private). I can't understand
I have some MovieClip class that has eventListener , added from inside the constructor
Hi I have some issue regarding constructor and destructor. I have list class, which
I have a base and derived class. The base class constructors have some static
I have some classes which are parameterized via their constructor. I need to provide
I have the following code: Some functions: A::A(int i_a) {cout<<int Ctor\n;} //conversion constructor void
if I have for example some class Base and derived from it Derived Also
Suppose I have some Message class like the following. (This is a made-up class
Suppose I have some class C , and I inherit from it and name

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.