PDA

View Full Version : qtScrollDial and QLCDNumber communication



saman_artorious
25th February 2013, 14:39
Let's consider this case\

I have three QtScrollDials, each representing one digit of a float number. the last one is for after-the-point digit.
I also have one QLCDNumber, what I am preferring to do is
when the operator sets each of these three QtScrollDials, the related digit in the QLCDNumber is changed accordingly.

droneone
26th February 2013, 01:09
I'm sure you can figure out how to update a number when its hundreds, tens, ones, and tenths change, so...

(I assume you're referring to the QtScrollDial demo widget)

Attach a slot to the dial's signal used to indicate a value change ( valueChanged(int) ), in that slot, get the current value of the QLCDNumber widget, update it appropriately, and then set the value back into the QLCDNumber widget.

saman_artorious
27th February 2013, 08:17
I have a problem here, I have 3 QtScrollDials inside X class. I edited the updateLabel slot of QtScrollDials class so when it updates the label it also sends a signal to X class, so that I can get its value and set my QLCDNumber accordingly.


void QtScrollDial::updateLabelValue()
{
m_label->setText(QString::number(value()));
emit updateDisplaySignal_valueChangedDahgan(value());
}


The problem I have is that I have 3 dials, not one, for each of these dials I need to emit 3 different signals so that I can understand which dial sent the signal.
do have any idea how I can do that?

Lesiok
27th February 2013, 08:27
Read aout QObject::sender

saman_artorious
27th February 2013, 08:49
Read aout QObject::sender

this is QtScrollDial SLOT:


void QtScrollDial::updateLabelValue()
{
m_label->setText(QString::number(value()));

emit updateDisplaySignal_valueChanged(value());
}


Inside X class
let's connect all 3 QtScrollDials to the above signal:


connect(myScrollDial, SIGNAL(updateDisplaySignal_valueChanged(int)), this, SLOT(scrollPopUp_valueChanged(int)));
connect(myScrollDial_2, SIGNAL(updateDisplaySignal_valueChanged(int)), this, SLOT(scrollPopUp_valueChanged(int)));
connect(myScrollDial_3, SIGNAL(updateDisplaySignal_valueChanged(int)), this, SLOT(scrollPopUp_valueChanged(int)));



inside the Slot I write this


QObject *sender = QObject::sender();
qDebug() << sender->objectName();



Everytime I run the program, sender gives me different addresses, and object name prints null.

Lesiok
27th February 2013, 10:33
You don't need sender name. Just compare sender address to myScrollDial, myScrollDial_2 and myScrollDial_3 to detect which digit You must change.