Printf to stream
Solved
General and Desktop
-
Hello,
I have this function:void app_trace_log(const char * format, ... ) {
//qDebug() << ???????????;
}The format argument uses printf like syntax for printing variable number of arguments (...). What's the easiest way to transform it to qt stream output (like qDebug())?
-
-
@SGaist How would you use QTextStream for this? The only solution I know goes like:
void app_trace_log(const char *format, ...) { va_list args; va_start(args, format); char *result; const int n = vasprintf(&result, format, args); va_end(args); if (n>=0) { qDebug() << result; free(result); } }
-
Sorry, I didn't meant it as drop-in replacement.
Thanks for the example.
Note that I'd rather recommend the use of QLoggingCategory for that kind of task.