QFile & QString().arg() Problems
Hello,
I've recently downloaded Qt 4.7 SDK (5 hours ago exactly), and trying it out, I see it's great, but I've came out with this little problem.
QStringQFile
I'm saving a file using QFile and some QStrings, but the strings in the file, are sometimes unrecognizeable, or a bunch of blank spaces.
Also, writting the string is like it isn't triggering the QString.arg() stuff, because I get %1, %2, %3, etc...
This is the code I use (I've just included the lines on which the error appears in the LUA file);
Code:
file.
write(QString("\t\tdoSetItemActionId(%1, %2)\n").
arg(item.
Name, item.
actionId).
toAscii().
constData());
file.
write(QString("\t\tlocal %1 = doCreateItemEx(cid, %2, %3)\n").
arg(item.
Name, item.
Id, item.
Amount).
toAscii().
constData());
file.
write(QString("\t\tlocal %1 = doCreateItemEx(cid, %2, %3)\n").
arg(item.
Name, item.
Id, item.
Amount).
toAscii().
constData());
Please sorry my english grammar, I'm just 17 year old.
Re: QFile & QString().arg() Problems
If you want to write QString to a file see QTextSream. It is much easier!
Re: QFile & QString().arg() Problems
It should be like this :
Code:
file.
write(QString("\t\tdoSetItemActionId(%1, %2)\n").
arg(item.
Name).
arg(item.
actionId).
toAscii().
constData());
one place holder (char % with number) one arg() calling with ONE value.
Re: QFile & QString().arg() Problems
Quote:
Originally Posted by
Lykurg
Thanks, but I still get the same problem, alot of espaces between the lines I specified, and I'm getting %1, %2.
And it's alot more easier thank you so much, I really see Qt and C++ much more easier than before.
Quote:
Originally Posted by
Lesiok
It should be like this :
Code:
file.
write(QString("\t\tdoSetItemActionId(%1, %2)\n").
arg(item.
Name).
arg(item.
actionId).
toAscii().
constData());
one place holder (char % with number) one arg() calling with ONE value.
Thank you, it's working now ;P