How i can handel changes in my application



  • Hi, every body

    i have a problem for choosing a solution to handle changes in my application

    means: when the user make some thing or change some thing in the application , and try to eixt the program

    i will pop up a message to inform him that , he has some changes

    i decided to use a boolean global variable , but i don't know that this way is correct



  • Can you post code snippet?



  • Global variables are almost never a correct solution, if you ask me.



  • Make a bool flag in class and a method modified() that only can set flag true. Whenever data change signal emitted in its connected slot call modified. In slot of close check flag if set then inform user.



  • [quote author="Tabi" date="1380631138"]Can you post code snippet?[/quote]

    I speak, in general way

    [quote author="Tabi" date="1380632644"]Make a bool flag in class and a method modified() that only can set flag true. Whenever data change signal emitted in its connected slot call modified. In slot of close check flag if set then inform user. [/quote]

    Yes this is what i mean, but if this is the right way

    [quote author="Andre" date="1380631804"]Global variables are almost never a correct solution, if you ask me.[/quote]

    So, what the correct solution ??



  • AFAIK, re-implement the close event for your Main Window.
    This is what I have done in my application.
    You have to maintain a private class variable or a static class variable for your Main Window class. I have used a bool variable which is a private class variable, since there are multiple windows in my application.

    What you have to do is maintain the value of this variable all throughout your application so that whenever close button is pressed by the user, you will check the value of the variable in the re-implemented function. If there is a change then show a message & ignore the close event. Else accept it.

    You can tinker around the help in Qt Creator for the exact code & understanding how to implement it.



  • Ok, i will try this methode , thanks a lot



  • http://qt-project.org/doc/qt-5.0/qtwidgets/richtext-textedit-textedit-cpp.html check out the implimentation of bool TextEdit::maybeSave() function. It is similar as CAD_coding explained.

    HTH.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.