0

In my Qt program I have a main window and a dialog window. The main window has options for the user to choose from and the dialog window which is called from the main window constructor asks the user for their password which it needs in order to perform its operations. I want to link the two windows in such a way that when the user tries to close out of the dialog window by pressing the standard X button in the upper right corner the whole program will close not just that window.

I think I found the answer to my problem here Qt: How do I handle the event of the user pressing the 'X' (close) button? and I copied the implementation of the overridden reject function and just changed MyDialog to the class name of my dialog window but for me I'm getting an error saying that no member function "reject()" has been declared in my dialog window class even though it has QDialog included #include and my dialog window class inherits from it all in the header file which is of course included in its cpp file.

Did I run into a funky bug with Qt? On a side note as it is I think it's a shame that the Qt devs never made those three standard buttons in the upper right corner predefined slots so the connect() function could be used instead.

Community
  • 1
  • 1
codehelp4
  • 132
  • 1
  • 2
  • 15

1 Answers1

0

Seems like you didn't add a declaration of the reject() method in your MyDialog header. If you want reimplement it, you should declare in the header:

public slots:
    virtual void reject();
Vladimir Bershov
  • 2,701
  • 2
  • 21
  • 51
  • That did it thanks. I didn't think I had to do that since it's suppose to be a function that defined in QDialog. Maybe it me that I specifically haven't worked with C++ in while but it's odd to me that when you inheriting from a class you have to write the declaration of any function you redefined in "your" header. Also if you or someone else could please help me in the code I linked where is the boolean value of the variable "changes" supposed to be determined. I could just initialize it to be true in the reject function but I don't see when it would ever change? (no pun intended lol) – codehelp4 Dec 27 '16 at 21:22
  • @codehelp4, the `changes` variable is not compulsory, in that example it likely is the `MyDialog` member and is initialized in the `MyDialog` 's constructor as `false`. Likely its meaning - whether made changes that require saving – Vladimir Bershov Dec 27 '16 at 21:32
  • @Valdimir Thanks for explaining that I wasn't sure if it was supposed to be something that's predefined by some library. I always tend to think that unless I see the declaration. – codehelp4 Dec 27 '16 at 22:51