如何在qt中使用带有两个参数的qDebug()?

How to use qDebug() with two parameters in qt?

我正在尝试使用带有两个参数的 qDebug() 但每次都失败。

我单独使用的时候没有问题,比如;

qDebug() << "img:width = " << img.width();
qDebug() << "img:height = " << img.height();

然而,当我将它们组合起来时,它给出了错误。

qDebug() << "img:width = " << img.width() << "/t img:height = " << img.height() << std::endl;

错误是:

error: no match for 'operator<<' in '((QDebug*)((QDebug*)((QDebug*)qDebug()().QDebug::operator<<(((const char*)"img:width = ")))->QDebug::operator<<(img.QImage::width()))->QDebug::operator<<(((const char*)"/t img:height = ")))->QDebug::operator<<(img.QImage::height()) << std::endl'

我可以在 qDebug 中使用两个或更多参数吗?

编辑::

如果我删除 std::endl

,问题仍然存在

删除行尾的std::endl,std::endl与std::cout结合使用,而不是与qDebug()

结合使用

这会起作用:

qDebug() << "img:width = " << img.width() << "/t img:height = " << img.height();

我认为您使用 /t 而不是 \t 是问题所在(我认为您正试图在两个项目之间放置一个制表符)。另外,是的,不需要 std::endl。

qDebug() << "img:width = " << img.width() << "\t" << "img:height = " << img.height();

或者

qDebug() << "img:width = " << img.width() << "\t img:height = " << img.height();

应该可以。