Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Object as global variable
Forum Updated to NodeBB v4.3 + New Features

Object as global variable

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 6 Posters 1.3k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C ChrisW67

    @MortyMars SIDs, STARs, and approaches ... welcome to my world :)

    MortyMarsM Offline
    MortyMarsM Offline
    MortyMars
    wrote on last edited by
    #7

    @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...

    C 1 Reply Last reply
    0
    • MortyMarsM MortyMars

      @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...

      C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #8

      @MortyMars I can imagine. They're a pain to design and describe in the first place.

      1 Reply Last reply
      0
      • SGaistS SGaist

        @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.

        MortyMarsM Offline
        MortyMarsM Offline
        MortyMars
        wrote on last edited by
        #9

        @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 ;-)

        SGaistS 1 Reply Last reply
        1
        • MortyMarsM MortyMars

          @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 ;-)

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #10

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          MortyMarsM 1 Reply Last reply
          0
          • SGaistS SGaist

            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.

            MortyMarsM Offline
            MortyMarsM Offline
            MortyMars
            wrote on last edited by
            #11

            @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...

            SGaistS 1 Reply Last reply
            0
            • MortyMarsM MortyMars

              @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...

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #12

              @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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              JonBJ 1 Reply Last reply
              0
              • SGaistS SGaist

                @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.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #13

                @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 which QStackedWidget would be perfect. But in his initial code notice he show()s them both. He then says

                and 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 --- QStackedWidget no good --- or do you only want one at a time --- in which case it's fine/recommended, but then don't start out show()ing both of them. So which is it?

                MortyMarsM 1 Reply Last reply
                0
                • JonBJ JonB

                  @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 which QStackedWidget would be perfect. But in his initial code notice he show()s them both. He then says

                  and 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 --- QStackedWidget no good --- or do you only want one at a time --- in which case it's fine/recommended, but then don't start out show()ing both of them. So which is it?

                  MortyMarsM Offline
                  MortyMarsM Offline
                  MortyMars
                  wrote on last edited by
                  #14

                  @JonB and @SGaist :

                  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.
                  And I don't need to have both displayed at the same time (since they don't fit on the screen anyway).

                  Pl45m4P 1 Reply Last reply
                  0
                  • MortyMarsM MortyMars

                    @JonB and @SGaist :

                    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.
                    And I don't need to have both displayed at the same time (since they don't fit on the screen anyway).

                    Pl45m4P Offline
                    Pl45m4P Offline
                    Pl45m4
                    wrote on last edited by
                    #15

                    @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 QStackedWidget as 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).


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    MortyMarsM 1 Reply Last reply
                    1
                    • Pl45m4P Pl45m4

                      @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 QStackedWidget as 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).

                      MortyMarsM Offline
                      MortyMarsM Offline
                      MortyMars
                      wrote on last edited by
                      #16

                      @Pl45m4 said in Object as global variable:

                      Then you could go with a QStackedWidget as 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 :-)

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved