Results 1 to 6 of 6

Thread: Translating a QStringList

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    69
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Translating a QStringList

    Hi,
    Is there anyway to transalte the contents of a QStringList automatically without have to transtale every QString item?

    I have a QStringList with a number of QStrings that have to be translated (I have the translator installed and the texts are translated). I'm using the "QTableWidget::setHorizontalHeaderLabels ( const QStringList & labels )" method. Is there a way to to this without having to get all the QStrings, transale them an put them into another QStringList ?

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Translating a QStringList

    Quote Originally Posted by ^NyAw^ View Post
    Is there anyway to transalte the contents of a QStringList automatically without have to transtale every QString item?
    No, there isn't. You can only use a trick such as this:

    Qt Code:
    1. QString str=tr("name,address,telephone number");
    2. QStringList slist = str.split(",");
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    69
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Translating a QStringList

    Hi,
    mmm, I think that you don't have understood me.

    In my QStringList there are i.e. 4 QStrings: "Area", "Center X", "Center Y", "Radius".
    I insert this QStringList as Horitzontal Header of a QTableWidget with the method "setHorizontalHeaderLabels" that takes a QStringList. I would to have the 4 items translated into the QStringList without having to do a bucle. The solution is easy:

    Qt Code:
    1. for (int i=0; i<qlist.count(); i++)
    2. {
    3. qtranslatedlist.insert(i,tr(qlist[i])); //Or something like this
    4. }
    To copy to clipboard, switch view to plain text mode 

    So, I would know if there is a method to translate all the QStrings with only one function.

    Thanks,
    Òscar Llarch i Galán

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Translating a QStringList

    Quote Originally Posted by ^NyAw^ View Post
    mmm, I think that you don't have understood me.
    Yes, I have

    So, I would know if there is a method to translate all the QStrings with only one function.
    If you require those strings to be separate, then no. But if it's not that necessary (and I think it's not), then you can use the method I suggested - put all labels into a single string, translate the string (in one go) and then split it into a string list.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Translating a QStringList

    Quote Originally Posted by ^NyAw^ View Post
    I would know if there is a method to translate all the QStrings with only one function.
    Yes, there is a way --- write such function yourself:
    Qt Code:
    1. QStringList Utils::tr( const QStringList & list )
    2. {
    3. QStringList result;
    4. foreach( const QString & str, list ) {
    5. result << QObject::tr( str );
    6. }
    7. return result;
    8. }
    To copy to clipboard, switch view to plain text mode 

    Other solution is to translate those strings before you add them to that list.

  6. #6
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    69
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Translating a QStringList

    Hi,
    Ok, thanks for replies.
    Òscar Llarch i Galán

Similar Threads

  1. QStringList in QObject::connect
    By DPinLV in forum Qt Programming
    Replies: 6
    Last Post: 6th September 2006, 18:01
  2. QStringList with Signal/Slot
    By Sivert in forum Qt Programming
    Replies: 4
    Last Post: 3rd May 2006, 21:34
  3. Cannot queue arguments of type 'QStringList'
    By vfernandez in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2006, 21:48
  4. qt4 QStringList with model/view
    By incapacitant in forum Newbie
    Replies: 23
    Last Post: 16th March 2006, 20:39
  5. need help to classify some QStringList
    By patcito in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 22: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.