All about programming in GNU/LINUX

Qt Creator:Illustration of signals and slots mechanism b/w Qslider and QSpinbox

ImageCreate a Empty QT C++ Project and compile and run the following code , which clearly illustrates the signals and slots mechanism using Spinbox and Slider widgets .As the horizontal slider value is changed the spinbox value is set to the new value of horizontal slider and vice-versa .

 

#include<QApplication>
#include<QHBoxLayout>
#include<QWidget>
#include<QSlider>
#include<QSpinBox>
int main(int argc,char **argv)
{
    QApplication app(argc,argv);
    QWidget *window=new QWidget;
    window->setWindowTitle(“Enter the marks”);
    QSlider *slider=new QSlider(Qt::Horizontal);
    QSpinBox *spinbox=new QSpinBox;
    spinbox->setRange(0,100);;
    slider->setRange(0,100);
    QObject::connect(spinbox,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));
    QObject::connect(slider,SIGNAL(valueChanged(int)),spinbox,SLOT(setValue(int)));
    spinbox->setValue(35);
    QHBoxLayout *layout=new QHBoxLayout;
    layout->addWidget(slider);
    layout->addWidget(spinbox);
    window->setLayout(layout);
    window->showNormal();
    return app.exec();
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s