Results 1 to 4 of 4

Thread: Cutting Elements QStringlist

  1. #1
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Cutting Elements QStringlist

    Hello friends I have to cut elements before transfer to DB:

    My approach is

    Qt Code:
    1. int i_fieldlength[]={4,2,4,40,8,6,5,3,8,1,5,3,7,8};
    2. for(int i =0; i < sizeof(i_fieldlength);i++){
    3. QString strbuf = splitlinelist.at(i);
    4. splitlinelist.at(i)=strbuf.left(i_fieldlength[i]);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Is there a more elegant way or faster way to do this???

    Ups this approach create an error:
    Qt Code:
    1. sources\tableeditor.cpp|917|error: passing `const QString' as `this' argument of `QString& QString::operator=(const QString&)' discards qualifiers|
    To copy to clipboard, switch view to plain text mode 

  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: Cutting Elements QStringlist

    You can use the database build in functions if your strings aren't too long. MySQL e.g supports
    Qt Code:
    1. q.prepare("...SET name = SUBSTRING(:str,0,:len)...");
    2. for(int i =0; i < sizeof(i_fieldlength)/sizeof(i_fieldlength[0]);++i)
    3. {
    4. q.bindValue(":str", splitlinelist.at(i));
    5. q.bindValue(":len", i_fieldlength[i]);
    6. q.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 

    NOTE: sizeof(i_fieldlength)/sizeof(i_fieldlength[0]) and ++i!

    EDIT: splitlinelist.at(i) => at() is constant so you can't assign a value to that. If you want to use the [] operator.

  3. #3
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Cutting Elements QStringlist

    I use mssql !

    And I do an insert but before I would like to cut the list...

  4. #4
    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: Cutting Elements QStringlist

    Quote Originally Posted by Lykurg View Post
    EDIT: splitlinelist.at(i) => at() is constant so you can't assign a value to that. If you want to use the [] operator.
    Quote Originally Posted by codeman View Post
    And I do an insert but before I would like to cut the list...
    then use the above mentioned:

    Qt Code:
    1. splitlinelist[i] = splitlinelist.at(i).left(i_fieldlength[i]);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QStringList
    By jaca in forum Qt Programming
    Replies: 5
    Last Post: 17th May 2008, 10:12
  2. Translating a QStringList
    By ^NyAw^ in forum Qt Programming
    Replies: 5
    Last Post: 18th January 2007, 11:06
  3. QStringList in QObject::connect
    By DPinLV in forum Qt Programming
    Replies: 6
    Last Post: 6th September 2006, 17:01
  4. Cannot queue arguments of type 'QStringList'
    By vfernandez in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2006, 20:48
  5. need help to classify some QStringList
    By patcito in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 21:24

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.