Diaries of Learning Qt (1.3) The maybeSave() Function

In my codes, I use a flag changed to mark whether the document has been modified:

 

MainWindow::MainWindow(QWidget *parent)

{

changed = false;

……

 

In fact, Qt provides a special method of QTextDocument(which is the type textEdit->document() points to)  :

 

bool QTextDocument::isModified()

 

which indicates whether the document has been modified.

And the maybeSave()  function is another common skill :

 

bool MainWindow::maybeSave()

{

    if (textEdit->document()->isModified()) {

        QMessageBox::StandardButton ret;

        ret = QMessageBox::warning(this, tr("Application"),

                     tr("The document has been modified.\n"

                        "Do you want to save your changes?"),

                     QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);

        if (ret == QMessageBox::Save)

            return save();

        else if (ret == QMessageBox::Cancel)

            return false;

    }

    return true;

}

To be specific, it shows the usage of a class:  QMessageBox.

Or, more specificly, a basic usage.

In this scrap, an enum type QMessageBox::StandardButton and a static method QMessageBox::warning.

StandardButton includes 19 kinds of common button like "Yes","No","Save","Discard"etc. and warning shows a dialog and return

the StandardButton the user choose.

 

转载于:https://www.cnblogs.com/Dolviet/p/7441132.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值