PDA

View Full Version : Multiple slots and signals



saad_saadi
8th August 2013, 10:06
Dear All,

I am newbie to Qt and found this forum very helpful whenever stuck in some problems. Today unfortunately i cannot find a suitable and matched answer to my question, so posting here for help.

I have four sliders in my project and i wants to connect them with four respective Bytes of same array.

connect(horizontalSlider_RED, SIGNAL(valueChanged(int)), this, SLOT(set_value_RED(int)));
connect(horizontalSlider_GREEN, SIGNAL(valueChanged(int)), this, SLOT(set_value_GREEN(int)));
connect(horizontalSlider_BLUE, SIGNAL(valueChanged(int)), this, SLOT(set_value_BLUE(int)));
connect(horizontalSlider_WHITE, SIGNAL(valueChanged(int)), this, SLOT(set_value_WHITE(int)));

In the set_value function they will not be processed just passed to another function with some other arguments. In the next function they will be like this

command[3] = value_RED;
command[4] = value_BLUE;
command[5] = value_WHITE;
command[6] = value_GREEN;

If you see in the slider portion of code that i can only send one argument and cannot send 4 argument. Here i want to send the output of 4 sliders simultaneously to the next function (set_value function), so that it will be processed appropriately.


Looking forward for a favorable response.

Thanks

karankumar1609
8th August 2013, 10:33
Please Paste your code for more understanding of your problem.

and please briefly explain your question.

Santosh Reddy
8th August 2013, 10:35
Hope this helps


class SliderWidget : public QWidget
{
Q_OBJECT
public:
explicit SliderWidget(QWidget * parent = 0)
: QWidget(parent)
, mRed(new QSlider(Qt::Horizontal))
, mBlue(new QSlider(Qt::Horizontal))
, mWhite(new QSlider(Qt::Horizontal))
, mGreen(new QSlider(Qt::Horizontal))
, mRedValue(new QLabel("0"))
, mBlueValue(new QLabel("0"))
, mWhiteValue(new QLabel("0"))
, mGreenValue(new QLabel("0"))
, mColorValue(new QLabel("0x00000000"))
{
QGridLayout * gridLayout = new QGridLayout(this);

gridLayout->addWidget(new QLabel("Red"), 0, 0, 1, 1);
gridLayout->addWidget(new QLabel("Blue"), 1, 0, 1, 1);
gridLayout->addWidget(new QLabel("White"), 2, 0, 1, 1);
gridLayout->addWidget(new QLabel("Green"), 3, 0, 1, 1);
gridLayout->addWidget(new QLabel("Color"), 4, 0, 1, 1);

gridLayout->addWidget(mRedValue, 0, 1, 1, 1);
gridLayout->addWidget(mBlueValue, 1, 1, 1, 1);
gridLayout->addWidget(mWhiteValue, 2, 1, 1, 1);
gridLayout->addWidget(mGreenValue, 3, 1, 1, 1);
gridLayout->addWidget(mColorValue, 4, 1, 1, 1);

gridLayout->addWidget(mRed, 0, 2, 1, 1);
gridLayout->addWidget(mBlue, 1, 2, 1, 1);
gridLayout->addWidget(mWhite, 2, 2, 1, 1);
gridLayout->addWidget(mGreen, 3, 2, 1, 1);

mRed->setRange(0, 255);
mBlue->setRange(0, 255);
mWhite->setRange(0, 255);
mGreen->setRange(0, 255);

connect(mRed, SIGNAL(valueChanged(int)), SLOT(updateValues()));
connect(mBlue, SIGNAL(valueChanged(int)), SLOT(updateValues()));
connect(mWhite, SIGNAL(valueChanged(int)), SLOT(updateValues()));
connect(mGreen, SIGNAL(valueChanged(int)), SLOT(updateValues()));
}

private slots:
void updateValues(void)
{
mRedValue->setText(QString::number(mRed->value()));
mBlueValue->setText(QString::number(mBlue->value()));
mWhiteValue->setText(QString::number(mWhite->value()));
mGreenValue->setText(QString::number(mGreen->value()));

QString val;
val += QString::number(mRed->value(), 16);
val += "," + QString::number(mBlue->value(), 16);
val += "," + QString::number(mWhite->value(), 16);
val += "," + QString::number(mGreen->value(), 16);
mColorValue->setText(val.toUpper());
}

private:
QSlider * mRed;
QSlider * mBlue;
QSlider * mWhite;
QSlider * mGreen;

QLabel * mRedValue;
QLabel * mBlueValue;
QLabel * mWhiteValue;
QLabel * mGreenValue;

QLabel * mColorValue;
};