QtSingleApplication QMessageBox yes 即使选择 no 也会采取行动

发布于 2024-09-16 10:15:13 字数 1751 浏览 0 评论 0原文

我在 Qt 中有一个应用程序,如果用户没有保存文档,它将覆盖关闭。它看起来像这样:

class MyApplication : public QtSingleApplication
{
    public:
    MyApplication(int argc, char *argv[]) : QtSingleApplication(argc, argv, true)
    {
    }

    ~MyApplication()
    {
    }

    void commitData(QSessionManager &manager)
    {
        if(manager.allowsInteraction())
        {
            main->RequestShutdownOverride();
        }
    }

    void SetMainWindow(MainWindow *m)
    {
        main = m;
    }

    MainWindow *main;
};

void MainWindow::RequestShutdownOverride()
{
    if(myDocument->hasChanges() == true)
    {
        switch
        (
          QMessageBox::warning
          (
             NULL, 
             "Foobar", 
             "You are exiting without saving.  Would you like to save?", 
             "Yes, save my document", "No, don't save my document", 
             0, 
             0, 
             1
          )
        )
        {
            case 0:
               myDocument->save();
            break;

            case 1:
               app->exit(0);
            break;
        }
    }
}

问题是对于几个用户来说,他们要关闭,关闭被覆盖,他们单击“否”,并且无论如何都会保存文档。我已经尝试对这段代码进行故障排除,但找不到任何明显的东西,更糟糕的是,如果我在他们的机器上创建自己的配置文件,它又可以正常工作了。

是否有什么代码方面我搞砸了,或者可能还有其他原因导致它?我尝试过切换 Qt 版本。这两个用户似乎唯一的另一个共同点是他们都使用 Windows Vista,但其他人使用 Vista 并没有报告此问题。有什么想法吗?

编辑

我正在使用这个定义:

static 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
)

I have an application in Qt that will override a shut down in case a user didn't save their document. It looks like this:

class MyApplication : public QtSingleApplication
{
    public:
    MyApplication(int argc, char *argv[]) : QtSingleApplication(argc, argv, true)
    {
    }

    ~MyApplication()
    {
    }

    void commitData(QSessionManager &manager)
    {
        if(manager.allowsInteraction())
        {
            main->RequestShutdownOverride();
        }
    }

    void SetMainWindow(MainWindow *m)
    {
        main = m;
    }

    MainWindow *main;
};

void MainWindow::RequestShutdownOverride()
{
    if(myDocument->hasChanges() == true)
    {
        switch
        (
          QMessageBox::warning
          (
             NULL, 
             "Foobar", 
             "You are exiting without saving.  Would you like to save?", 
             "Yes, save my document", "No, don't save my document", 
             0, 
             0, 
             1
          )
        )
        {
            case 0:
               myDocument->save();
            break;

            case 1:
               app->exit(0);
            break;
        }
    }
}

The problem is for a couple of users they go to shut down, the shut down is overridden they click "no" and it saves the document anyway. I've tried troubleshooting this code and I can't find anything obvious, and worse - if I create a profile of my own on their machine it works fine again.

Is there anything code-wise that I've screwed up, or could there be something else causing it? I've tried switching Qt versions. The only other thing that these two users seem to have in common is that they both use windows vista, but others use vista and haven't reported this problem. Any ideas?

EDIT

I'm using this definition:

static 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
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

余生共白头 2024-09-23 10:15:13

快速浏览一下 TrollTech 的文档,它似乎我认为 0 没有返回。他们的示例是使用您没有使用的 exec() 函数调用,但我猜想无论哪种方式,返回值都保持不变。

想到的另一件事是,如果您只是使用窗口上的关闭按钮关闭对话框,会发生什么?

Having a quick look at the docs at TrollTech it appears to me that 0 is not returned. Their example is using the exec() function call which you're not using, but I'd guess the return values remain the same either way.

The other thing that pops into mind is what happens if you simply close the dialog using the close button on the window?

飞烟轻若梦 2024-09-23 10:15:13

QMessageBox::warning()的返回值为enum QMessageBox::StandardButton 因此您必须查找这些来查看对话框是如何关闭的。

The return value of QMessageBox::warning() is enum QMessageBox::StandardButton so you would have to look for those to see how the dialog was closed.

哥,最终变帅啦 2024-09-23 10:15:13

问题原来是用户的个人资料上安装了恶意软件。

Problem turned out to be malware installed on the user's profile.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文