当执行特定的测试用例时,我必须在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中弹出消息窗口?
发布评论