PDA

View Full Version : QFile & QString().arg() Problems



Jonathan Maen
21st January 2012, 09:31
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);



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.

Lykurg
21st January 2012, 10:28
If you want to write QString to a file see QTextSream. It is much easier!

Lesiok
21st January 2012, 13:46
It should be like this :
file.write(QString("\t\tdoSetItemActionId(%1, %2)\n").arg(item.Name).arg(item.actionId).toAscii().cons tData());
one place holder (char % with number) one arg() calling with ONE value.

Jonathan Maen
21st January 2012, 21:15
If you want to write QString to a file see QTextSream. It is much easier!

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.


It should be like this :
file.write(QString("\t\tdoSetItemActionId(%1, %2)\n").arg(item.Name).arg(item.actionId).toAscii().cons tData());
one place holder (char % with number) one arg() calling with ONE value.

Thank you, it's working now ;P