Obsolete Members for QMessageBox

QMessageBox 类的以下成员已被废弃。提供这些成员是为了确保旧的源代码能够继续运行。我们强烈建议不要在新代码中使用它们。

公共类型

(deprecated) Button

公共函数

(deprecated) QMessageBox(const QString &title, const QString &text, QMessageBox::Icon icon, int button0, int button1, int button2, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint)
(deprecated in 6.2) QString buttonText(int button) const
(deprecated in 6.2) void setButtonText(int button, const QString &text)

静态公共成员

(deprecated in 6.2) int critical(QWidget *parent, const QString &title, const QString &text, int button0, int button1, int button2 = 0)
(deprecated in 6.2) int critical(QWidget *parent, const QString &title, const QString &text, const QString &button0Text, const QString &button1Text = QString(), const QString &button2Text = QString(), int defaultButtonNumber = 0, int escapeButtonNumber = -1)
(deprecated in 6.2) int information(QWidget *parent, const QString &title, const QString &text, int button0, int button1 = 0, int button2 = 0)
(deprecated in 6.2) int information(QWidget *parent, const QString &title, const QString &text, const QString &button0Text, const QString &button1Text = QString(), const QString &button2Text = QString(), int defaultButtonNumber = 0, int escapeButtonNumber = -1)
(deprecated in 6.2) int question(QWidget *parent, const QString &title, const QString &text, int button0, int button1 = 0, int button2 = 0)
(deprecated in 6.2) int question(QWidget *parent, const QString &title, const QString &text, const QString &button0Text, const QString &button1Text = QString(), const QString &button2Text = QString(), int defaultButtonNumber = 0, int escapeButtonNumber = -1)
(deprecated in 6.2) QPixmap standardIcon(QMessageBox::Icon icon)
(deprecated in 6.2) int warning(QWidget *parent, const QString &title, const QString &text, int button0, int button1, int button2 = 0)
(deprecated in 6.2) int warning(QWidget *parent, const QString &title, const QString &text, const QString &button0Text, const QString &button1Text = QString(), const QString &button2Text = QString(), int defaultButtonNumber = 0, int escapeButtonNumber = -1)

成员类型文档

[deprecated] QMessageBox::Button

此 typedef 已弃用。我们强烈建议不要在新代码中使用它。

请改用 `QMessageBox::StandardButton `。

成员函数文档

[deprecated] QMessageBox::QMessageBox(const QString &title, const QString &text, QMessageBox::Icon icon, int button0, int button1, int button2, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint)

此函数已弃用。我们强烈建议不要在新代码中使用它。

创建一个包含title 、text 、icon 以及最多三个按钮的消息框。

icon 必须是以下选项之一:

每个按钮(button0 、button1 和button2 )均可取以下值之一:

若要使消息框中的按钮数量少于三个,请在后续参数中使用QMessageBox::NoButton 。如果完全未指定任何按钮,QMessageBox 将提供一个“确定”按钮。

其中一个按钮可与QMessageBox::Default 标志进行“或”运算,使其成为默认按钮(按下 Enter 键时自动点击该按钮)。

可以将其中一个按钮与QMessageBox::Escape 标志进行或运算,使其成为“取消”或“关闭”按钮(按Esc 键时点击该按钮)。

QMessageBox mb("Application Name",
               "Hardware failure.\n\nDisk error detected\nDo you want to stop?",
               QMessageBox::Question,
               QMessageBox::Yes | QMessageBox::Default,
               QMessageBox::No | QMessageBox::Escape,
               QMessageBox::NoButton);
if (mb.exec() == QMessageBox::No) {
    // try again

该消息框是一个application modal 对话框。

parent 和f 参数会被传递给QDialog 构造函数。

另请参阅 setWindowTitle()、setText() 和setIcon()。

[deprecated in 6.2] QString QMessageBox::buttonText(int button) const

自 6.2 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。

返回消息框按钮button 的文本,如果消息框中不包含该按钮,则返回空字符串。

请改用 `button()` 和 `QPushButton::text()`。

另请参阅 setButtonText()。

[static, deprecated in 6.2] int QMessageBox::critical(QWidget *parent, const QString &title, const QString &text, int button0, int button1, int button2 = 0)

自 6.2 版本起,此函数已弃用。我们强烈建议不要在新代码中使用它。

请改用接受 `StandardButtons ` 的重载版本。

使用给定的title 和text 打开一个关键级别的消息框。该对话框最多可包含三个按钮。每个按钮参数button0 、button1 和button2 均可设置为以下值之一:

若不希望显示全部三个按钮,请将最后一个按钮或最后两个按钮设置为QMessageBox::NoButton 。

其中一个按钮可与QMessageBox::Default 进行“或”运算,另一个按钮可与QMessageBox::Escape 进行“或”运算。

返回被点击按钮的标识符(QMessageBox::Ok 、QMessageBox::No 等)。

该消息框是一个application modal 对话框。

警告: 在对话框执行期间请 勿删除 `parent `。若需执行此操作,应使用 `QMessageBox ` 的构造函数之一自行创建对话框。

另请参阅 information()、question() 和warning()。

[static, deprecated in 6.2] int QMessageBox::critical(QWidget *parent, const QString &title, const QString &text, const QString &button0Text, const QString &button1Text = QString(), const QString &button2Text = QString(), int defaultButtonNumber = 0, int escapeButtonNumber = -1)

自 6.2 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。

请改用接受 `StandardButtons ` 参数的重载版本。

显示一个关键错误消息框,其中包含给定的title 和text ,以及一个、两个或三个按钮。返回被点击的按钮编号(0、1 或 2)。

button0Text 是第一个按钮的文本,可选。如果未提供button0Text ,将使用“OK”(已翻译)。button1Text 是第二个按钮的文本,可选;button2Text 是第三个按钮的文本,可选。defaultButtonNumber (0、1 或 2) 是默认按钮的索引;按下 Return 或 Enter 键等同于点击该默认按钮。默认值为 0(第一个按钮)。escapeButtonNumber 是 Escape 按钮的索引;按下 Escape 键等同于点击该按钮。 默认值为 -1;若需使按下 Escape 键等同于单击相关按钮,请指定 0、1 或 2。

该消息框是一个application modal 对话框。

警告: 在对话框执行期间,请 勿删除parent 。若需执行此操作,应使用QMessageBox 构造函数之一自行创建对话框。

这是一个重载函数。

另请参阅 information()、question() 和warning()。

[static, deprecated in 6.2] int QMessageBox::information(QWidget *parent, const QString &title, const QString &text, int button0, int button1 = 0, int button2 = 0)

自 6.2 版起,该函数已被废弃。我们强烈建议不要在新代码中使用它。

请改用接受 `StandardButtons ` 作为参数的重载版本。

打开一个包含给定title 和text 的信息对话框。该对话框最多可包含三个按钮。每个按钮(button0 、button1 和button2 )均可设置为以下值之一:

若不希望显示全部三个按钮,请将最后一个按钮或最后两个按钮设置为QMessageBox::NoButton 。

其中一个按钮可与QMessageBox::Default 进行“或”运算,另一个按钮可与QMessageBox::Escape 进行“或”运算。

返回被点击按钮的标识符(QMessageBox::Ok 、QMessageBox::No 等)。

该消息框是一个application modal 对话框。

警告:请 勿在对话框执行期间删除 `parent `。若需执行此操作,应使用 `QMessageBox ` 的其中一个构造函数自行创建对话框。

另请参阅 question()、warning() 和critical()。

[static, deprecated in 6.2] int QMessageBox::information(QWidget *parent, const QString &title, const QString &text, const QString &button0Text, const QString &button1Text = QString(), const QString &button2Text = QString(), int defaultButtonNumber = 0, int escapeButtonNumber = -1)

自 6.2 版起,此函数已被废弃。我们强烈建议不要在新代码中使用它。

请改用接受 `StandardButtons ` 参数的重载版本。

显示一个包含给定的title 和text 的信息消息框,以及一个、两个或三个按钮。返回被点击的按钮的索引(0、1或2)。

button0Text 是第一个按钮的文本,可选。如果未提供button0Text ,则使用“OK”(已翻译)。button1Text 是第二个按钮的文本,可选。button2Text 是第三个按钮的文本,可选。defaultButtonNumber (0、1 或 2) 是默认按钮的索引;按下 Return 或 Enter 键等同于点击该默认按钮。默认值为 0(第一个按钮)。escapeButtonNumber 是逃逸按钮的索引;按下Esc 等同于点击该按钮。 其默认值为 -1;若指定 0、1 或 2,则按下Esc 键将等同于单击相应的按钮。

消息框是一个application modal 对话框。

警告: 在对话框执行期间,请 勿删除parent 。如果要这样做,应使用QMessageBox 构造函数之一自行创建对话框。

这是一个重载函数。

另请参阅 question()、warning() 和critical()。

[static, deprecated in 6.2] int QMessageBox::question(QWidget *parent, const QString &title, const QString &text, int button0, int button1 = 0, int button2 = 0)

自 6.2 版本起,此函数已弃用。我们强烈建议不要在新代码中使用它。

请改用接受 `StandardButtons ` 参数的重载版本。

打开一个问题消息框,其中包含给定的title 和text 。该对话框最多可包含三个按钮。每个按钮(button0 、button1 和button2 )均可设置为以下值之一:

若不希望显示全部三个按钮,请将最后一个按钮或最后两个按钮设置为QMessageBox::NoButton 。

其中一个按钮可与QMessageBox::Default 进行“或”运算,另一个按钮可与QMessageBox::Escape 进行“或”运算。

返回被点击按钮的标识符(QMessageBox::Yes 、QMessageBox::No 等)。

该消息框是一个application modal 对话框。

警告: 在对话框执行期间请 勿删除 `parent `。若需删除,应使用 `QMessageBox ` 的构造函数之一自行创建对话框。

另请参阅 information()、warning() 和critical()。

[static, deprecated in 6.2] int QMessageBox::question(QWidget *parent, const QString &title, const QString &text, const QString &button0Text, const QString &button1Text = QString(), const QString &button2Text = QString(), int defaultButtonNumber = 0, int escapeButtonNumber = -1)

自 6.2 版起,此函数已弃用。我们强烈建议不要在新代码中使用它。

请改用接受 `StandardButtons ` 参数的重载版本。

显示一个问题消息框,其中包含给定的title 和text ,以及一个、两个或三个按钮。返回被点击的按钮的索引(0、1 或 2)。

button0Text 是第一个按钮的文本,为可选参数。如果未提供button0Text ,则使用“OK”(已翻译)。button1Text 是第二个按钮的文本,为可选参数。button2Text 是第三个按钮的文本,为可选参数。defaultButtonNumber (0、1 或 2) 是默认按钮的索引;按下 Return 或 Enter 键等同于点击该默认按钮。默认值为 0(第一个按钮)。escapeButtonNumber 是 Escape 按钮的索引;按下 Escape 键等同于点击该按钮。 默认值为 -1;指定 0、1 或 2 可使按下 Escape 键等同于单击相应的按钮。

该消息框是一个application modal 对话框。

警告: 在对话框执行期间,请 勿删除parent 。若需执行此操作,应使用QMessageBox 的构造函数之一自行创建对话框。

这是一个重载函数。

另请参阅 information()、warning()和critical()。

[deprecated in 6.2] void QMessageBox::setButtonText(int button, const QString &text)

自 6.2 版本起,此函数已弃用。我们强烈建议不要在新的代码中使用它。

将消息框按钮button 的文本设置为text 。若设置的按钮不在消息框内,则该设置将被静默忽略。

请改用addButton()。

另请参阅 buttonText()。

[static, deprecated in 6.2] QPixmap QMessageBox::standardIcon(QMessageBox::Icon icon)

自 6.2 版本起,此函数已弃用。我们强烈建议在新代码中不要使用它。

返回用于标准图标的消息图。这使得该消息图可用于更复杂的消息框中。icon 指定所需的图标,例如QMessageBox::Question 、QMessageBox::Information 、QMessageBox::Warning 或QMessageBox::Critical 。

请改用QStyle::SP_MessageBoxInformation 等参数调用QStyle::standardIcon()。

[static, deprecated in 6.2] int QMessageBox::warning(QWidget *parent, const QString &title, const QString &text, int button0, int button1, int button2 = 0)

自 6.2 版本起,此函数已弃用。我们强烈建议不要在新代码中使用它。

请改用接受 `StandardButtons ` 的重载版本。

使用给定的title 和text 打开一个警告消息框。该对话框最多可包含三个按钮。每个按钮的参数button0 、button1 和button2 均可设置为以下值之一:

若不希望显示全部三个按钮,请将最后一个按钮或最后两个按钮设置为QMessageBox::NoButton 。

其中一个按钮可以与QMessageBox::Default 进行“或”运算,另一个按钮可以与QMessageBox::Escape 进行“或”运算。

返回被点击按钮的标识符(QMessageBox::Ok 或QMessageBox::No 或……)。

该消息框是一个application modal 对话框。

警告: 在对话框执行期间请 勿删除parent 。若需删除,应使用QMessageBox 的构造函数之一自行创建对话框。

另请参阅 information()、question() 和critical()。

[static, deprecated in 6.2] int QMessageBox::warning(QWidget *parent, const QString &title, const QString &text, const QString &button0Text, const QString &button1Text = QString(), const QString &button2Text = QString(), int defaultButtonNumber = 0, int escapeButtonNumber = -1)

自 6.2 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。

请改用接受 `StandardButtons ` 作为参数的重载版本。

显示一个警告消息框,其中包含给定的title 和text ,以及一个、两个或三个按钮。返回被点击的按钮编号(0、1 或 2)。

button0Text 是第一个按钮的文本,可选。如果未提供button0Text ,则使用“OK”(已翻译)。button1Text 是第二个按钮的文本,可选;button2Text 是第三个按钮的文本,可选。defaultButtonNumber (0、1 或 2) 是默认按钮的索引;按下 Return 或 Enter 键相当于单击该默认按钮。默认值为 0(第一个按钮)。escapeButtonNumber 是 Escape 按钮的索引;按下 Escape 键相当于单击该按钮。 默认值为 -1;若指定 0、1 或 2,则按下 Escape 键即等同于单击相应按钮。

该消息框是一个application modal 对话框。

警告: 在对话框执行期间,请 勿删除parent 。若需执行此操作,应使用QMessageBox 的构造函数之一自行创建对话框。

这是一个重载函数。

另请参阅 information()、question() 和critical()。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.