PDA

View Full Version : Pass QString array to constructor



Ozzy
4th February 2014, 09:28
Hi, I try program a menu based on a double linked list. Each menu-item is an Object of e.g. type "header" or "item". Now I want to support several languages for the menu. I thought to pass an array with the text in different languages to the constructor when creating the node. Is this a good approach?

And my second question is how pass an array 'directly' when creating the object like


Node *node1 = new Node( {"language1", "language2"}, type, ... );


when I have a QString array.

Best regards
Christoph

ChrisW67
4th February 2014, 20:36
Qt has has complete support for translating the labels and other static text in your program using Linguist
Internationalization in Qt
You might want to look at that before you reinvent a wheel.

To pass a collection of QStrings (there are none in your example) you could pass a const reference to a QStringList or QVector<QString>. You can create a QStringList in situ with:

blah(QStringList() << QString("a") << QString("b"));