[Development] New feature to qstring | QString::toBool()

jan-arve.saether at nokia.com jan-arve.saether at nokia.com
Wed Oct 26 09:15:59 CEST 2011


ext Frans Klaver wrote on 2011-10-26:

> On Wed, Oct 26, 2011 at 8:31 AM,  <jan-arve.saether at nokia.com> wrote:
> 
>> Consider this code:
>> 
>> bool parseOk;
>> if (str.toBool(&parseOk)) {
>>    if (parseOk)
>>        enableSuperFastRenderer();
>> }
> 
> I think that in most, if not all cases, the parseOk argument would or
> even should be omitted (just like with QVariant):
> 
> if (str.toBool()) {
>     enableSuperFastRenderer();
> }
> 
> because the results will be exactly the same as your example.
> 
>> then this:
>> 
>> if (str == QLatin1String("true")) {
>>    enableSuperFastRenderer();
>> }
>> 
>> which would you prefer?
> 
> I ask you the same question.
> 
Ok, so toBool() will return false if it fails.

Then you would need the not-so-nice code for checking for false:

bool parseOk;
if (!str.toBool(&parseOk)) {
   if (parseOk)
       disableSuperFastRenderer();
}


regards,
Jan-Arve




More information about the Development mailing list