3

Under Qt5.9 and clang++-6.0.0,

QString ret;
qFatal(ret.toLatin1().constData());

yields a warning "format string is not a string literal".

What's wrong, and what is the right way to accomplish the required conversion from QString to a C string?

PS: A closely related question is Converting QString to char*. Here, however, different solutions are possible thanks to the printf-like argument list of qFatal.

Joachim W
  • 7,290
  • 5
  • 31
  • 59

1 Answers1

2

qFatal allows for the variadic ... argument known from printf. Thus

qFatal("%s", ret.toLatin1().constData());

and the warning is gone.

Joachim W
  • 7,290
  • 5
  • 31
  • 59