Reading the value of a QSpinBox
Hi,
sounds simple and probabaly it is... but... Newbie...
I have a QSpinBox (name property in Qt Designer is s1). According to the documentation
http://doc.trolltech.com/3.2/qspinbox.html#value
I want to read its value.
Now I have a singal/slot which connects a QPushbutton with a LCD display. If I push the button I want to display the value of the spinBox inside the LCD. Inside my ...ui.h FIle I have the follwoing code:
void Form1::display_result()
{
int value1 =5;
value1= s1.value(); // here is the problem
result -> display(value1); // result is my LCD element, this line works
}
The compiler complains:
In file included from form1.cpp:28:
form1.ui.h: In member function `virtual void Form1::display_result()':
form1.ui.h:18: error: request for member `value' in `this->Form1::s1', which is of non-aggregate type `QSpinBox*'
make: *** [form1.o] Error 1
Any idea?
Regards,
Jochen
Re: Reading the value of a QSpinBox
Re: Reading the value of a QSpinBox
Quote:
Originally Posted by jochen_r
Hi,
void Form1::display_result()
{
int value1 =5;
value1= s1.value(); // here is the problem
result -> display(value1); // result is my LCD element, this line works
}
The compiler complains:
In file included from form1.cpp:28:
form1.ui.h: In member function `virtual void Form1::display_result()':
form1.ui.h:18: error: request for member `value' in `this->Form1::s1', which is of non-aggregate type `QSpinBox*'
make: *** [form1.o] Error 1
Any idea?
Regards,
Jochen
The problem is that s1 is a pointer to a QSpinBox object. Replace it with the following:
Code:
value1= s1->value();
Don't you love descriptive compiler errors?
:D
Edit: As you can tell, I've gotten this error quite a few times myself.
Re: Reading the value of a QSpinBox
Re: Reading the value of a QSpinBox
Thanks jakamph, that's it!
This was the complete code.
Regards,
Jochen