Hi to all,
I can't believe that, it's missing a capitalizing function in Qt!!!
Does anyone suggest a quick way to do it?
Thanks in advance.
Printable View
Hi to all,
I can't believe that, it's missing a capitalizing function in Qt!!!
Does anyone suggest a quick way to do it?
Thanks in advance.
The doc it your friend. Use it! QString::toUpper()
I hope you don't want to pull my leg. Where is the problem in combining that with normal c++ rules?
Uhm, the docs clearly state that TeXt turns into TEXT. If this isn't the case, either you have done something wrong or there's a bug in Qt. Since they have a QTestLib example built around this exact function, I am pretty sure you have done something wrong.
Edit: I really should pay a bit more attention. The question really wasn't clear enough but you noticed it yourself after lykurg's reply...
There's no function to change the first character of a string to upper case because such a function makes little sense in many languages; it is a task specific mainly to Western languages and alphabets. In today's global, Unicode world the majority of readers would find such a function useless.
If that's all you need, however, however, myString[0].toUpper() will get you there. Feel free to define a macro, or a function, or simply hard-code the solution wherever it's needed.
You can use QFont::setCapitalization(). I guess the rationale is that it's a rendering step.
Reid
Hi,
I guess you want to capitalize all nouns in a sentence, as is common for titles in English.
Use the split method of QString, using a space as separator. This gives you a list of strings. toUpper() each first character of each string in the stringlist. Then concatenate all the strings back together, putting a space in between them.
You could add exceptions that the words 'and' and 'or' and such are not capitalized.
Best regards,
Marc
I usually do:
Code:
str = str.left(1).toUpper()+str.mid(1);