Problem with lcdNumber
-
I want to display an lcdNumber on my beaglebone onboard display.
I have 2 module: CwWindow and I2CCW
Class CwWindow:public QMainWindow, private Ui::CwWindow
Private slots:
void updatef();
// signal-slot connection:
connect(pushButton, SIGNAL(clicked() ), this, SLOT(updatef() ) );
...
voidCwWindow::updatef() {
I2CCW m_i2ccw; //object for Modul I2CCW
m_i2ccw.get_sum();Module I2CCW has no signal-slot, and give only the correct value ´dB´ back to module CwWindow.
void I2CCW::get_sum() {
double dB = ....
CwWindow cw; //object for module CwWindow
cw.show_recPo(dB) ;// in module CwWindow
void CwWindow::show_recPo(double dB) {
recPo = dB;
std.cout << recPo << ´\nˋ // give correct value ( -49.3)
lcdNumber->display(recPo); //give value 0 !!!!When I give a number in slot function:
void CwWindow::updatef() {
lcdNumber->display(-49.3); //value is displayed correct
What can I do to get the correct display in function
show_recPo() ?? -
@iq0-0
QLCDNumber::display(double value)
does not work in one place and then fail to work in another. Remove all your signal & slot connections. Just trydouble db = -49.3; lcdNumber->display(recPo);
in both places. Make sure your
lcdNumber
instances are the same actual widget. -
QLCDNumber::display()
is unfortunately an ambiguous slot, taking either an int or a double. That can have surprising effects, especially when dealing with PMF based connections.Using
qOverload<double>(&QLCDNumber::display)
in the connect statement should solve such issues. -
@Axel-Spoerl said in Problem with lcdNumber:
QLCDNumber::display()
is unfortunately an ambiguous slot, taking either an int or a double. That can have surprising effects, especially when dealing with PMF based connections.I don't see how that's relevant, given that slot is not being connected to (it's being invoked directly). Of course, it might well be relevant, I'm just not sure why. Would love to hear more if its something I'm missing :) Either way
qOverload()
is pretty cool - never knew about that one.@iq0-0, what is your
QLCDNumber::mode
set to? OnlyQLCDNumber::Dec
supports floating points, the other are integer only.Assuming you are using
QLCDNumber::Dec
, I would set a break-point on this line:cdNumber->display(recPo); //give value 0 !!!!
And then step into and through that function call. It's possible, for example, that:
recPo
is being modified by some other code in between yourqDebug
andQLCDNumber::display()
calls (we don't see the declaration, nor the full life-cycle of that member variable; do you have multi-threaded or async I/O happening? is that variable adouble
?); orQLCDNumber::display()
might be setting the value correctly, and later calls overwriting it to0
before you see the results;- etc.
As I said, I'd use the debugger to step into it, and if that doesn't reveal anything, then what @JonB suggested above. Or try @JonB's suggestion first. Either is good, IMO :)
Cheers.
-
@JonB
Thank you for your replies.
I tried by removing all signal & slot connections.
In function ‚‘void CwWindow::show_recPo(double dB)‘ the
result was ‚‘0‘ instead of the correct value (-49.3). The difference
to with signal & slot was that ‚‘0‘ did not move to the left.In function ‚‘void CwWindow::updatef()‚‘ the resultat also is ‚‘0‘ .![alt text]([image url]([link url](![link url](image url))))
-
My mode is set to ‚‘QLCDNumber::Dec ‚‘. ‚‘RecPo’ is the correct double number.
The problem is that the object ‚‘lcdNumber‚‘ ‚is not the same in the function ‚‘show_recPo(double dB) ‚‘ and in the slot ‚‘updatef()‚‘ .
Whereas when I give a number in the slot ‚‘ updatef()‚‘ , ‚‘lcdNumber->display(number) ‚‘
the display gives the correct number and in the function ‚‘show_recPo(double dB)‚‘
it displays ‚‚‘0‘ . -
Hi,
You call show_recPo in get_sum which uses a local object if type CwWindow hence it will to nothing to your main CwWindow.