I am using the Qt plugin for Eclipse and I am following one of the tutorials for Qt 4.3.
I have this:
void cannonfield::setAngle(int angle)
{
if (angle < 5)
angle = 5;
if (angle > 70)
angle = 70;
if (currentAngle == angle)
return;
currentAngle = angle;
update();
emit angleChanged(currentAngle);
}
void cannonfield
::paintEvent(QPaintEvent * /* event */) {
painter.
drawText(200,
200, tr
("Angle = ") + QString::number(currentAngle
));
}
void cannonfield::setAngle(int angle)
{
if (angle < 5)
angle = 5;
if (angle > 70)
angle = 70;
if (currentAngle == angle)
return;
currentAngle = angle;
update();
emit angleChanged(currentAngle);
}
void cannonfield::paintEvent(QPaintEvent * /* event */)
{
QPainter painter(this);
painter.drawText(200, 200, tr("Angle = ") + QString::number(currentAngle));
}
To copy to clipboard, switch view to plain text mode
setAngle is called by:
void lcdrange::on_horizontalSlider_valueChanged(int value)
{
ui.lcdNumber->display(value);
this->setValue(value);
ui.cannon->setAngle(value);
}
void lcdrange::on_horizontalSlider_valueChanged(int value)
{
ui.lcdNumber->display(value);
this->setValue(value);
ui.cannon->setAngle(value);
}
To copy to clipboard, switch view to plain text mode
The program will run. However, when it is run, nothing is displayed I am trying to get the angle value to be displayed in the "cannonfield" widget. The cannonfield widget is there, but the angle is not displayed. I put:
printf("test");
printf("test");
To copy to clipboard, switch view to plain text mode
into the paintEvent method and nothing is displayed in the console when I move the slider around. However, after I close the window, losts of "test"s are displayed.
Also, how does the keyword "emit" work?
Thanks.
Bookmarks