Answer the question
In order to leave comments, you need to log in
How to make only one child window instance open?
Subject. The same window can be opened from different panels/menus, so keeping a link to the window object somewhere in one place is not very good. Pushing it into a singleton also seems not very good. Store a static reference to an object inside the class of the window itself? It's not pretty either. How is it done by professional grandfathers in general, is there a good elegant way practiced?
Answer the question
In order to leave comments, you need to log in
How are you displaying the window? You most likely create a new object with new, set some parameters for it, and call show().
If you want at most one instance of the window to be visible, you can't create objects with new, you must call some function that will give you a ready-made object (new or already existing). How it will be implemented is up to you. The simplest is a global variable. Then you can hide it in the MainWindow class and issue it on request through the public MainWindow method. The advantage of this approach is that you can make MainWindow the parent of this object, which means that it will automatically be deleted when the program ends and will also be displayed along with the main window. You can also make a singleton, but here you need to carefully monitor when it will be created and whether it will be deleted later.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question