PDA

View Full Version : Reading the value of a QSpinBox



jochen_r
10th January 2006, 05:04
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

MarkoSan
10th January 2006, 08:04
Show the complete code.

jakamph
10th January 2006, 08:25
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:



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.

MarkoSan
10th January 2006, 08:59
Give me the header file.

jochen_r
10th January 2006, 13:25
Thanks jakamph, that's it!

This was the complete code.

Regards,
Jochen