Results 1 to 4 of 4

Thread: QFile & QString().arg() Problems

  1. #1
    Join Date
    Jan 2012
    Posts
    12
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default 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);

    Qt Code:
    1. file.write(QString("\t\tdoSetItemActionId(%1, %2)\n").arg(item.Name, item.actionId).toAscii().constData());
    2.  
    3. file.write(QString("\t\tlocal %1 = doCreateItemEx(cid, %2, %3)\n").arg(item.Name, item.Id, item.Amount).toAscii().constData());
    4.  
    5. file.write(QString("\t\tlocal %1 = doCreateItemEx(cid, %2, %3)\n").arg(item.Name, item.Id, item.Amount).toAscii().constData());
    To copy to clipboard, switch view to plain text mode 

    Please sorry my english grammar, I'm just 17 year old.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QFile & QString().arg() Problems

    If you want to write QString to a file see QTextSream. It is much easier!

  3. The following user says thank you to Lykurg for this useful post:

    Jonathan Maen (23rd January 2012)

  4. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile & QString().arg() Problems

    It should be like this :
    Qt Code:
    1. file.write(QString("\t\tdoSetItemActionId(%1, %2)\n").arg(item.Name).arg(item.actionId).toAscii().constData());
    To copy to clipboard, switch view to plain text mode 
    one place holder (char % with number) one arg() calling with ONE value.

  5. #4
    Join Date
    Jan 2012
    Posts
    12
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFile & QString().arg() Problems

    Quote Originally Posted by Lykurg View Post
    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.

    Quote Originally Posted by Lesiok View Post
    It should be like this :
    Qt Code:
    1. file.write(QString("\t\tdoSetItemActionId(%1, %2)\n").arg(item.Name).arg(item.actionId).toAscii().constData());
    To copy to clipboard, switch view to plain text mode 
    one place holder (char % with number) one arg() calling with ONE value.
    Thank you, it's working now ;P

Similar Threads

  1. Som problems about unicode,QString and QTextEdit
    By furskytl in forum Qt Programming
    Replies: 2
    Last Post: 28th October 2011, 14:21
  2. Problems reading content of QFile
    By martinn in forum Newbie
    Replies: 12
    Last Post: 6th April 2010, 18:42
  3. Problems with QString::simplified() API
    By montylee in forum Qt Programming
    Replies: 2
    Last Post: 20th June 2009, 04:14
  4. Problems with QString
    By cyberboy in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2008, 08:18
  5. QFile and QTextStream problems
    By uchennaanyanwu in forum Newbie
    Replies: 0
    Last Post: 7th August 2008, 02:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.