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.
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()
Cupidvogel (7th January 2016)
I hope you don't want to pull my leg. Where is the problem in combining that with normal c++ rules?Qt Code:
{ QString tmp = str; // if you want to ensure all other letters are lowercase: tmp = tmp.toLower(); tmp[0] = str[0].toUpper(); return tmp; }To copy to clipboard, switch view to plain text mode
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...
Last edited by franz; 18th July 2010 at 19:57.
Horse sense is the thing that keeps horses from betting on people. --W.C. Fields
Ask Smart Questions
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:
Qt Code:
str = str.left(1).toUpper()+str.mid(1);To copy to clipboard, switch view to plain text mode
frankiefrank (7th November 2012)
Bookmarks