开发者

Qt - getting "warning: format not a string literal and no format arguments"

开发者 https://www.devze.com 2023-01-27 13:07 出处:网络
Keep getting warnings on lines like these qDebug(\"An error occured while trying to create folder \" + workdir.toAscii());

Keep getting warnings on lines like these

qDebug("An error occured while trying to create folder " + workdir.toAscii());

wor开发者_开发知识库kdir being QString()

warning: format not a string literal and no format arguments


That should probably be:

qDebug("An error occured while trying to create folder %s", workdir.constData());

since qDebug takes const char* as first argument.


When debbuging with qDebug, I find the following syntax much easier :

qDebug() << "An error occured while trying to create folder" << workdir;

To do this, you'll need to include the <QtDebug> header.

More info : Qt docs regarding qDebug().


I managed to get it to work fine without warning like this :

qDebug("An error occurred while trying to create folder %s", qUtf8Printable(workdir));
0

精彩评论

暂无评论...
验证码 换一张
取 消