Results 1 to 2 of 2

Thread: Pass QString array to constructor

  1. #1
    Join Date
    Nov 2007
    Posts
    21
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Pass QString array to constructor

    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
    Qt Code:
    1. Node *node1 = new Node( {"language1", "language2"}, type, ... );
    To copy to clipboard, switch view to plain text mode 

    when I have a QString array.

    Best regards
    Christoph

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Pass QString array to constructor

    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:
    Qt Code:
    1. blah(QStringList() << QString("a") << QString("b"));
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Pass struct array to function
    By willbeas_SMU in forum General Programming
    Replies: 2
    Last Post: 19th March 2012, 17:05
  2. Cast QString array to std::string array
    By Ishtar in forum Newbie
    Replies: 4
    Last Post: 15th July 2011, 08:28
  3. Pass a QString as args for commandProcess
    By mikemakus in forum Newbie
    Replies: 2
    Last Post: 3rd December 2009, 23:03
  4. How to pass a QString to another class ?
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 9th December 2006, 20:16
  5. how can I pass a QString to vsnprintf?
    By coralbird in forum Newbie
    Replies: 6
    Last Post: 18th January 2006, 08:32

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.