PDA

View Full Version : Different result if slot is called from 'Return' or 'Tab'Key in a QLineEdit.



gboelter
18th October 2010, 16:19
Guys and - of course - girls,

I'm going crazy today so I hope somebody can help me ...

With this code


QObject::connect ( lineEditRabatt,
SIGNAL( editingFinished() ), this,
SLOT( showPreis() ));

this slot is called ....



void Angebot::showPreis()
{
qDebug() << "I'm in showPreis() now to recalculate the final price ...";

lineEditMenge->setText( QString( "%1" ).arg( lineEditMenge->text().toFloat(), 0, 'f', 2 ) );
lineEditBrutto->setText( QString( "%1" ).arg( lineEditBrutto->text().toFloat(), 0, 'f', 2 ) );

if ( lineEditRabatt->text().contains ( QChar( '%' ), Qt::CaseInsensitive ) )
{
lineEditRabatt->setText( QString( "%1" ).arg( ( lineEditBrutto->text().toFloat() * lineEditRabatt->text().remove( QChar( '%' ),
Qt::CaseInsensitive).toFloat() ) / 100, 0, 'f', 2 ) );
}
else
{
lineEditRabatt->setText( QString( "%1" ).arg( lineEditRabatt->text().toFloat(), 0, 'f', 2 ) );
}

lineEditNetto->setText( QString( "%1" ).arg( lineEditBrutto->text().toFloat() - lineEditRabatt->text().toFloat(), 0, 'f', 2 ) );
lineEditGesamt->setText( QString( "%1" ).arg( lineEditNetto->text().toFloat() * lineEditMenge->text().toFloat(), 0, 'f', 2 ) );

if ( lineEditMenge->text().toFloat() > 0 )
pushButtonBuchen->setEnabled ( true );
}


And now my problem: After I have entered the amount of 'Rabatt' in lineEditRabatt I will leave the lineEdit either with 'Return' or with 'Tab'. If editingFinished() was caused by the 'Tab-Key' everything is ok. But if the last key was the 'Return-Key', then 'lineEditRabatt->text().toFloat()' is igrnored in row 18. It's not zero, it's really ignored ...

Any idea where I'm wrong?

gboelter
19th October 2010, 05:08
Got it ...

There was a QPushButton with 'Return' as a shortcut and the pushButton was executed first.