What's your Qt's version? This code works fine for me.
What's your Qt's version? This code works fine for me.
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
it is Qt 4.8.1 ... you mean you got the spaces after the name like
"Student Name******** = jemes" ??
I'm also using 4.8.1 and I've got such output:
int main(int, char**) " Student Name = James"
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
the editor eat the space but, i see the spaces you got same which is in the front : "********Student Name = James"
but the result i want is "Student Name******** = James" .
"*": means space
see Oleg's post above.![]()
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
From the docs:
So, tryfieldWidth specifies the minimum amount of space that argument a shall occupy. If a requires less space than fieldWidth, it is padded to fieldWidth with character fillChar. A positive fieldWidth produces right-aligned text. A negative fieldWidth produces left-aligned text.
Oleg Shparber
The documentation for QString::arg() specifies that if the fieldWidth argument is positive (which is the case in your example), then you will get right-aligned text. This is why spaces are inserted on the left.
Also, do not use .arg().arg().arg()! Can you see what would happen if a student decided to put "%1" in their name? (BTW I just realized that the example in the docs makes this mistake.)
I would use QString("%1 = %2").arg(name, value) or QString("%1 = %2").arg(QString("%1").arg(name, -20), value) for a left-aligned padded student name.
Bookmarks