gpt4 book ai didi

c++ - QMessageBox使用快捷键多次打开

转载 作者:太空宇宙 更新时间:2023-11-04 05:41:23 24 4
gpt4 key购买 nike

我将 QMesssageBox 与 CTRL + N 快捷键内联(这意味着将打开新文件)。当我在对象动画时按住快捷键时。这是 Linux 的 UI 问题吗,因为我使用的是 Linux 操作系统,然后我在其他操作系统中尝试,但它没有发生,或者我忘记了任何代码?谢谢。

最佳答案

如果您的目标是一次最多出现一个 QMessageBox,您可以通过以下方式确保在代码中:

static QMessageBox * openMBox = NULL;

void MyClass :: showMessageBox()
{
if (openMBox) return; // don't open a new QMessageBox if we already have one open!

openMBox = new QMessageBox(args here...);
connect(openMBox, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(userClickedButton(QAbstractButton*)));
openMBox->show();
}

void MyClass :: userClickedButton(QAbstractButton * button)
{
if (openMBox)
{
// [code to handle button-click result could go here]

openMBox->deleteLater();
openMBox = NULL;
}
}

请注意,如果 openMBox 为 NULL(也就是说,仅当尚不存在消息框时),showMessageBox() 才会实际创建一个新的 QMessageBox

(The code calls deleteLater() in the userClickedButton() method instead of using the delete operator because it's likely that the userClickedButton() method is itself being called from within a method of the QMessageBox object, therefore we don't want to delete the QMessageBox object until later when it's not in the middle of a method-call)

关于c++ - QMessageBox使用快捷键多次打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55645129/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com