当执行特定的测试用例时,我必须在Qt中弹出一条消息。由于我是Qt的初学者,所以我不想冒险尝试qml ...
我如何做(直接在.cpp文件中)而不创建qml文件?
如果要显示简单消息,可以使用QMessageBox :: information。
通过提供的链接,您可以通过以下方式调用该类型的消息框:
QMessageBox::information(
this,
tr("Application Name"),
tr("An information message.") );
编辑:由于这几年来这个问题有很多访问,我只是想为了信息而包括其他类型的消息(同样,通过上面的链接获取):
QMessageBox::warning(
this,
tr("Application Name"),
tr("A warning message.") );
QMessageBox::critical(
this,
tr("Application Name"),
tr("A critical message.") );
switch( QMessageBox::question(
this,
tr("Application Name"),
tr("An information message."),
QMessageBox::Yes |
QMessageBox::No |
QMessageBox::Cancel,
QMessageBox::Cancel ) )
{
case QMessageBox::Yes:
qDebug( "yes" );
break;
case QMessageBox::No:
qDebug( "no" );
break;
case QMessageBox::Cancel:
qDebug( "cancel" );
break;
default:
qDebug( "close" );
break;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句