Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Constant QString Messages



  • Hello,

    In my software I have many QString messages used in dialog or message boxes.
    They are all constant.
    Could you please confirm that the best way is to define them in my class as private const members and initialize them in the cpp where I use them ?

    Many thanks


  • Lifetime Qt Champion

    Hi,

    These strong aren't part of your API so I'd rather put them only in the cpp file as static const QString generated with QStringLiteral.



  • if you have many QString, and you can not make sure their count or text, you can save them to file, such as .xml

    <Message id="1" text="hello">
    <Message id="2" text="world">

    then, you can load text by id


Log in to reply