简体   繁体   English

如何将QMessageBox文本重定向到文本文件

[英]How to redirect QMessageBox text to a Textfile

In my project lots of time i am using QMessageBox. 在我的项目中,很多时间我都在使用QMessageBox。 which is for warning / information . 用于警告/信息。 For eg If i am having some validation then at that time i am using some QMessageBox::information(…) , or if i want to restrict the user not to move out of a particular page then i am using QMessageBox::critical(…) . 例如,如果我进行一些验证,那么那时我正在使用一些QMessageBox :: information(…),或者如果我想限制用户不要移出特定页面,那么我正在使用QMessageBox :: critical(… )。 I know “How to redirect qDebug output to a file”.I want to do the same thing for the QMessagebox too. 我知道“如何将qDebug输出重定向到文件”。我也想对QMessagebox做同样的事情。 so that i will maintain a text file in my project folder . 这样我就可以在项目文件夹中维护一个文本文件。 whenever the application run if the user encounters some message through QMessagebox , then that shall be redirected to that text file .So that after closing the application the user have a small list of messagedetails ,whatever he has encountered during running the application . 每当应用程序运行时,如果用户通过QMessagebox遇到某些消息,则应将其重定向到该文本文件。这样,在关闭应用程序后,用户将拥有一小列消息详细信息,无论他在运行该应用程序时遇到了什么。

Please help me in writting this code .. 请帮我写这段代码..

Thankxx in advance . 提前谢谢。

You can declare your own static information, warning and critical functions that will show original QMessageBox and also write something to log. 您可以声明自己的静态信息,警告和关键功能,这些功能将显示原始QMessageBox并编写一些日志记录。

static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton);

StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons, StandardButton defaultButton) 
{
   qDebug() << "writing to log";
   return QMessageBox::information (parent, title, text, buttons, defaultButton)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM