tags:

views:

53

answers:

4

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
)
A: 

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?

Matti
Still seems to work fine if I hit the close button... I didn't see the enums there, I'll try them instead since that's clearer anyway. Thanks.
jjacksonRIAB
A: 

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.

Arnold Spence
I'm not using standard buttons. I added a definition for the overloaded version of warning I'm calling to my post. I don't use button2Text so that is 0, default button is button 0, escape button is mapped to button 1, which is cancel.
jjacksonRIAB
OK. I see your edit now with the definition. What does the implementation do?
Arnold Spence
The implementation works, for the most part. It's an application in production with over 500 users. Unfortunately two users have a problem where if they shut down it asks them to save, they select no, and it saves anyway. But if they just exit and don't shut down, it runs the same code and works fine.At this point I'm suspecting either those two have malware, corrupt profiles or 3rd party applications of some sort that are causing problems because I've logged in under my own profile on their machines and it works correctly...
jjacksonRIAB
A: 

Try changing the first parameter of QMessageBox::warning from NULL to this. I remember having some weird messagebox behavior because of that, but I can't guarantee it will help. But at least then your messagebox will be centered at the mainwindow which looks better.

Roku
A: 

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

jjacksonRIAB