C++ 如何在QT中使用DEBUG对齐日志文件中的数据?

C++ 如何在QT中使用DEBUG对齐日志文件中的数据?,c++,qt,debugging,alignment,display,C++,Qt,Debugging,Alignment,Display,我想在QT应用程序的日志文件中显示数据。为此,我使用DEBUG() 我显示的数据是: Time since beginning of the test (ms) : 751 Pressure : "0.051547" Time since beginning of the test (ms) : 2498 Pressure : "0.116169" Time since beginning of the test (ms) : 8498 Pressure : "0.2537

我想在QT应用程序的日志文件中显示数据。为此,我使用
DEBUG()

我显示的数据是:

Time since beginning of the test (ms) :  751  Pressure :  "0.051547" 
Time since beginning of the test (ms) :  2498  Pressure :  "0.116169" 
Time since beginning of the test (ms) :  8498  Pressure :  "0.253792" 
Time since beginning of the test (ms) :  10497  Pressure :  "0.290243" 
Time since beginning of the test (ms) :  12597  Pressure :  "0.316798"
但是我想把变量对齐,就像它们是列一样。 我想要这样的东西:

Time since beginning of the test (ms) :    751  Pressure :  "0.051547" 
Time since beginning of the test (ms) :   2498  Pressure :  "0.116169" 
Time since beginning of the test (ms) :   8498  Pressure :  "0.253792" 
Time since beginning of the test (ms) :  10497  Pressure :  "0.290243" 
Time since beginning of the test (ms) :  12597  Pressure :  "0.316798"
我使用的代码是:

for (int i = 0 ; i < _pressureValues.length() ; i++)
{
    DEBUG() << "Time since beginning of the test (ms) : " << _pressureValues[i].first
            << " Pressure : " << _pressureValues[i].second;
}
for(int i=0;i<_pressureValues.length();i++)
{

DEBUG()您不能直接使用DEBUG()执行此操作-您需要事先格式化输出字符串。 例如,具有
QString QString::arg(双a,int fieldWidth=0,char format='g',int precision=-1,QChar fillChar=QLatin1Char(“”))函数,该函数允许您格式化数字

for (int i = 0 ; i < _pressureValues.length() ; i++)
{
    const QString firstPressureValue = QString("%1").arg(_pressureValues[i].first, 5);
    DEBUG() << "Time since beginning of the test (ms) : " << firstPressureValue 
        << " Pressure : " << _pressureValues[i].second;
}
for(int i=0;i<_pressureValues.length();i++)
{
常量QString firstPressureValue=QString(“%1”).arg(_pressureValues[i].first,5);

DEBUG()什么是
DEBUG()
?是的,忘了说那句话。它与
qDebug()
相同,但除了控制台之外,它还写在我的日志文件中
QString debugString = QString("Time since beginning of the test (ms) : %1 Pressure : %2");
QString firstPressureValue = QString("%1").arg(_pressureValues[i].first, 5);
DEBUG() << debugString.arg(firstPressureValue, QString::number(_pressureValues[i].second));