如何在Qt中弹出消息窗口? [英] How to pop up a message window in Qt?

查看:3077
本文介绍了如何在Qt中弹出消息窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当执行特定的测试用例时,我必须在Qt中弹出一条消息。由于我是Qt的初学者,所以我不想冒险尝试使用qml ...

I have to pop up a message in Qt when a particular test case is executed. Since I am a beginner in Qt, I do not want to risk trying with a qml...

如何在不创建的情况下(直接在.cpp文件中)进行操作一个qml文件?

How can I do it (directly in .cpp file) without creating a qml file?

推荐答案

如果要显示简单消息,可以使用 QMessageBox :: information

If you want to display a simple message, you can use a QMessageBox::information.

按照提供的链接,您可以通过以下方式调用该类型的消息框:

Following the provided link, you can call a message box of that type this way:

QMessageBox::information( 
    this, 
    tr("Application Name"), 
    tr("An information message.") );

编辑:由于这些问题在这些年来吸引了很多访问,我只是想为了信息而包括其他类型的消息(同样,由上面的链接获取):

Since this question had a lot of visits during these years, I just wanted to include the other types of message for the sake of information (again, taken by the link above):

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;
}

这篇关于如何在Qt中弹出消息窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆