Check string length before accesing first character.
Fixes Qt ASSERT which happens when string length == 0