Search code examples
c++qtqdebug

How to call qDebug without the appended spaces and newline?


I'm using the the C++/Qt print function qDebug, but sometimes I would like to control how ", space and newline is appended and not use the default qDebug.

Let's take a simple example:

QString var1("some string");
int var2 = 1;
qDebug() << var1 << "=" << var2;

This will print

"some string" = 1 

But Let's say that I don't like the appended " and space and would like the print to look like

some string=1 

How to I then call qDebug?


Note: There is a function in qDebug called nospace, but it will remove the spaces. But the " is still there.

If I use this:

qDebug().nospace() << var1 << "=" << var2;

I get:

"some string"=1

But please note that I have still not found a way to get rid of the ending newline.

/Thanks


Solution

  • Try this format: qDebug("%s=%d", "string", 1); In this case qDebug uses printf formatting

    P.S. Adapted for your example: qDebug("%s=%d", var1.toStdString().c_str(), var2);