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. accessing elements of header file in other windows
Qt 6.11 is out! See what's new in the release blog

accessing elements of header file in other windows

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 1.5k Views 1 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.
  • N Offline
    N Offline
    nasir
    wrote on last edited by
    #1
    This post is deleted!
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      That's rather a C++ question. Why do you want to do it like that ? Global variables like that should rather be avoided as much as possible.

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

      N 1 Reply Last reply
      2
      • N Offline
        N Offline
        nasir
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          That's rather a C++ question. Why do you want to do it like that ? Global variables like that should rather be avoided as much as possible.

          N Offline
          N Offline
          nasir
          wrote on last edited by
          #4

          @SGaist i want to access this variable in all the other windows of project. thats why i want to make it public.

          JonBJ 1 Reply Last reply
          0
          • N nasir

            @SGaist i want to access this variable in all the other windows of project. thats why i want to make it public.

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

            @nasir
            Ignoring the question of whether it is good design or not, I would have expected the line you show in your "main window" file should read int Nodecount = 8;. Make sure that does not change the error? If not: it would be an error to meet such a line more than once in a file, are you sure you do not have another line in your main window file which defines the variable?

            Also, in your main source file: are you including the "random" header file before the line where you try to define the variable?

            It's also best when you have a compile error to show the actual error message together with the actual line of source the error message mentions.

            N 1 Reply Last reply
            1
            • JonBJ JonB

              @nasir
              Ignoring the question of whether it is good design or not, I would have expected the line you show in your "main window" file should read int Nodecount = 8;. Make sure that does not change the error? If not: it would be an error to meet such a line more than once in a file, are you sure you do not have another line in your main window file which defines the variable?

              Also, in your main source file: are you including the "random" header file before the line where you try to define the variable?

              It's also best when you have a compile error to show the actual error message together with the actual line of source the error message mentions.

              N Offline
              N Offline
              nasir
              wrote on last edited by
              #6
              This post is deleted!
              aha_1980A JonBJ 2 Replies Last reply
              0
              • N nasir

                This post is deleted!

                aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by aha_1980
                #7

                @nasir why don't you just try it?

                Qt has to stay free or it will die.

                1 Reply Last reply
                1
                • N nasir

                  This post is deleted!

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

                  @nasir
                  It has no effect on what is in the header file one way or the other. It is indeed defining & setting the initial value of the variable declared in the header file. You can indeed access that variable from any other file where you include that header file.

                  1 Reply Last reply
                  1

                  • Login

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