如何将QDebug()与QT中的两个参数一起使用

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

本文关键字:两个 参数 一起 QDebug QT      更新时间:2023-10-16

我试图使用两个参数使用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();

应该工作。