1

Consider below code:

static constexpr QString FOO = QStringLiteral("foo"); // erro compile , because QString has not default destructor.

How I can create QString at compile time!? is it possible to create QString at compile time?

H.M
  • 425
  • 2
  • 16
  • 1
    [Qt vs constexpr string literal](https://stackoverflow.com/questions/56201976/qt-vs-constexpr-string-literal) – Drew Dormann Feb 14 '22 at 19:51
  • https://code.woboq.org/qt5/qtbase/src/corelib/text/qstring.h.html#QLatin1String 1-QLatin1String has not virtual destructor 2- I won't write more class because I want reduce overhead , this create compexity ... (maybe not now ) @DrewDormann – H.M Feb 14 '22 at 20:08

2 Answers2

1

In Qt 6.2 you can use the new u"my string"_qs syntax. https://doc.qt.io/qt-6/qstring.html#operator-22-22_qs

ecloud
  • 326
  • 2
  • 3
1

Before Qt6 you can use:

constexpr QStringView FOO = u"foo";
magrif
  • 396
  • 4
  • 20