How to call qDebug without the appended spaces and newline?

后端 未结 7 1818
耶瑟儿~
耶瑟儿~ 2020-12-13 08:33

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

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-13 09:05

    I also experienced the quotes problem. The solution is to not pipe QString() into the stream but instead QString(...).toStdString().c_str().

    I've built myself a small convenience macro to easily get around this:

    #define Q(string) (string).toStdString().c_str()
    

    Now everytime you use a QString, do it like that:

    qDebug() << Q(var1) << "=" << var2;
    

提交回复
热议问题