Object as global variable
-
@MortyMars SIDs, STARs, and approaches ... welcome to my world :)
@ChrisW67 said in Object as global variable:
@MortyMars SIDs, STARs, and approaches ... welcome to my world :)
I'm trying to develop a tool to help edit approach files for X-Plane 12, because it's not impossible to do by hand, but it's pretty tedious...
-
@ChrisW67 said in Object as global variable:
@MortyMars SIDs, STARs, and approaches ... welcome to my world :)
I'm trying to develop a tool to help edit approach files for X-Plane 12, because it's not impossible to do by hand, but it's pretty tedious...
@MortyMars I can imagine. They're a pain to design and describe in the first place.
-
@MortyMars hi and welcome to devnet,
The usual answer would be: proper architecture.
If you use global variable for ease of access then you are doing something very wrong.
@SGaist said in Object as global variable:
@MortyMars hi and welcome to devnet,
The usual answer would be: proper architecture.
If you use global variable for ease of access then you are doing something very wrong.
Hi SGaist,
After a few fruitless searches on the net, I have to admit that I'd be interested in a bit more detail about an alternative solution to global variables and the right architecture to put in place as you mention....
Thank you for any leads you can give me ;-)
-
@SGaist said in Object as global variable:
@MortyMars hi and welcome to devnet,
The usual answer would be: proper architecture.
If you use global variable for ease of access then you are doing something very wrong.
Hi SGaist,
After a few fruitless searches on the net, I have to admit that I'd be interested in a bit more detail about an alternative solution to global variables and the right architecture to put in place as you mention....
Thank you for any leads you can give me ;-)
Well, the first thing to do is to identify why you think you need global variables.
What is your application architecture ?
What are you using them for ?From there we can iterate to improve your architecture.
-
Well, the first thing to do is to identify why you think you need global variables.
What is your application architecture ?
What are you using them for ?From there we can iterate to improve your architecture.
@SGaist said in Object as global variable:
Well, the first thing to do is to identify why you think you need global variables.
What is your application architecture ?
What are you using them for ?From there we can iterate to improve your architecture
Thanks for your feedback.
My application is based around two windows that can be called up from each other. Each of these windows needs to be unique and remain for the entire life of the application, as data is entered in them and needs to be preserved.
I use the show() and hide() methods to hide and recall them, but the show() method (probably badly used) creates new objects of the window class each time I call it up and doesn't allow me to recall the two original windows.
Global variables seemed to me to be the solution for creating a lasting link and pointing to these two famous windows for sure.
If there's an alternative way of creating this durable link, then my problem is solved...
-
@SGaist said in Object as global variable:
Well, the first thing to do is to identify why you think you need global variables.
What is your application architecture ?
What are you using them for ?From there we can iterate to improve your architecture
Thanks for your feedback.
My application is based around two windows that can be called up from each other. Each of these windows needs to be unique and remain for the entire life of the application, as data is entered in them and needs to be preserved.
I use the show() and hide() methods to hide and recall them, but the show() method (probably badly used) creates new objects of the window class each time I call it up and doesn't allow me to recall the two original windows.
Global variables seemed to me to be the solution for creating a lasting link and pointing to these two famous windows for sure.
If there's an alternative way of creating this durable link, then my problem is solved...
@MortyMars ok so first, take a look at QStackedWidget which allows you to easily switch between multiple widgets.
I don't know about the data you need to share but it makes me think of the model view architecture. Your widgets are the views and you share a model between the two. Give your widgets as setModel method, store the model pointer in each of and voila, your global variable need has been eliminated.
-
@MortyMars ok so first, take a look at QStackedWidget which allows you to easily switch between multiple widgets.
I don't know about the data you need to share but it makes me think of the model view architecture. Your widgets are the views and you share a model between the two. Give your widgets as setModel method, store the model pointer in each of and voila, your global variable need has been eliminated.
@SGaist said in Object as global variable:
ok so first, take a look at QStackedWidget which allows you to easily switch between multiple widgets.
I did not suggest this because: initially the OP talked about
show()&hide(), so only one window/widget at a time. For whichQStackedWidgetwould be perfect. But in his initial code notice heshow()s them both. He then saysand I want to be able to switch from one window to the other and back to the first
It took it to mean he wants to see both at the same time. But we can't tell.
@MortyMars Simple question: do you want both windows visible at same time ---
QStackedWidgetno good --- or do you only want one at a time --- in which case it's fine/recommended, but then don't start outshow()ing both of them. So which is it? -
@SGaist said in Object as global variable:
ok so first, take a look at QStackedWidget which allows you to easily switch between multiple widgets.
I did not suggest this because: initially the OP talked about
show()&hide(), so only one window/widget at a time. For whichQStackedWidgetwould be perfect. But in his initial code notice heshow()s them both. He then saysand I want to be able to switch from one window to the other and back to the first
It took it to mean he wants to see both at the same time. But we can't tell.
@MortyMars Simple question: do you want both windows visible at same time ---
QStackedWidgetno good --- or do you only want one at a time --- in which case it's fine/recommended, but then don't start outshow()ing both of them. So which is it? -
@MortyMars said in Object as global variable:
In fact I have two different windows, mainly to display data masks that don't fit in a single window.
The two windows are the same size and overlap perfectly.I can't see how this works or why one window won't....
The two windows are the same size and overlap perfectly.
And I don't need to have both displayed at the same time (since they don't fit on the screen anyway).Then you could go with a
QStackedWidgetas recommended by @SGaist .
You just simply replace / change the widget from one window instead of showing two windows which have a "static" widget.(since they don't fit on the screen anyway).
I mean, this is no excuse ;-)
Since you are the developer, you can make them fit ;-)
There are plenty techniques to do so (layouts, scroll areas... etc). -
@MortyMars said in Object as global variable:
In fact I have two different windows, mainly to display data masks that don't fit in a single window.
The two windows are the same size and overlap perfectly.I can't see how this works or why one window won't....
The two windows are the same size and overlap perfectly.
And I don't need to have both displayed at the same time (since they don't fit on the screen anyway).Then you could go with a
QStackedWidgetas recommended by @SGaist .
You just simply replace / change the widget from one window instead of showing two windows which have a "static" widget.(since they don't fit on the screen anyway).
I mean, this is no excuse ;-)
Since you are the developer, you can make them fit ;-)
There are plenty techniques to do so (layouts, scroll areas... etc).@Pl45m4 said in Object as global variable:
Then you could go with a
QStackedWidgetas recommended by @SGaist .I see that @SGaist's QStackedWidget solution is unanimously approved.
So I'm going to take a closer look :-)(since they don't fit on the screen anyway).
I mean, this is no excuse ;-)
Since you are the developer, you can make them fit ;-)My only excuse is that I'm just a modest occasional developer ;-)
But the way my application is organised makes ergonomic sense.Thanks for your help :-)