Qt-interest Archive, March 2002
AW: QString and latin1() question
Message 1 in thread
try to build the commandstring this way:
QString string( QString( string2 ) + str );
and then pass string.latin1() to the function.
I know that doesn't answer the question what went wrong with your way of
implementing it, but if it works that way then just do it that way.
Tom
-----Ursprüngliche Nachricht-----
Von: Phil [mailto:phil@spiderweb.com.au]
Gesendet: Dienstag, 12. März 2002 10:20
An: qt-interest@trolltech.com
Betreff: QString and latin1() question
Hello All,
A search through the archives shows that this type of question has been
asked
many times before but I still can't see the answer to my problem.
I have a function that takes a parameter like this:
function(char "command");
The problem is that I have to built up the command string from a character
array and a qstring along the following lines.
char string[25];
char string2 = {"some text "};
QString str = "here";
const char *string3 = str.latin1();
/* Build a command string */
sprintf(string,"%s %s","string2",string3);
If I now pass string to my function then the function fails (the function is
part of a library and not my own code).
I notice that the kdevelop debugger shows string like this:
"some text here\000\000\000"
If I code something like this then there isn't a problem, string = {"some
text here"}, and the debugger show this:
"some text here"
I have spent most of the day trying to sort this out and have tried may
variations without a usable result. I'm sure that the answer is a simple
one.
--
[ signature omitted ]
Message 2 in thread
>> QString str = "here";
>>
>> const char *string3 = str.latin1();
>>
>> /* Build a command string */
>> sprintf(string,"%s %s","string2",string3);
>>
>This should be OK.
Uhm... well... you didn't look close enough... even this is not OK...
because he quoted "string2" which would produce "string2here". ;-)
Tom