如何在Qt中弹出消息窗口?

编程入门 行业动态 更新时间:2024-10-28 20:17:29
本文介绍了如何在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中弹出消息窗口?

本文发布于:2023-08-06 05:05:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1310244.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:弹出   窗口   消息   如何在   Qt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!