[Qt-interest] QString (hex) to unsigned int conversion
Carel Combrink
carel.combrink at gmail.com
Wed Dec 22 10:34:57 CET 2010
Hi,
Is there an easy way to convert a QString containing a hex value to integer.
See example below:
bool ok;
ui->lineEdit->setText("0xABCD");
//ui->lineEdit->setText("0xabcd");
//ui->lineEdit->setText("43981");
unsigned int value = ui->lineEdit->text().toUInt(&ok);
if(ok)
{
// use the value
}else
{
// give error
}
The context is I want the user to enter a value in the lineEdit. The value
should either be in the format of an integer (ex. '1') or a hex value (ex.
'0x001'). The code must then get the value and use the value obtained. Using
any of the setText functions (uncomment any one) the value of 'value' should
be the same.
Is there an easy way of doing this using Qt?
Thank you,
Carel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101222/bfd90658/attachment.html
More information about the Qt-interest-old
mailing list