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. Global variable help
Qt 6.11 is out! See what's new in the release blog

Global variable help

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 2.3k 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.
  • T Offline
    T Offline
    Tyler1234
    wrote on last edited by
    #1

    I need to make a variable and have it be assessable form all my .cpp files. how do I do this?

    Or a way to send a variable to another file so it can be accessed.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      There are several techniques for that but it's generally discourage. Why do you need that global variable ?

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

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tyler1234
        wrote on last edited by
        #3

        I have a person login to an account and then I need to detect which account the person logged into, but the account number is on one cpp file and The place I need to check is on another cpp file, so I need to make a way to acsess the variable from both cpp files

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then you should rather look after the singleton pattern

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

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nnead
            wrote on last edited by
            #5

            you could try to solve your problem by single/slot mechanism, just connect your login with both .cpp files

            @connect(client,SIGNAL(login()),this,SLOT(check4id()));@

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Tyler1234
              wrote on last edited by
              #6

              Could you explain more on how to do this?

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Which technique ?

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

                1 Reply Last reply
                0
                • IamSumitI Offline
                  IamSumitI Offline
                  IamSumit
                  wrote on last edited by
                  #8

                  Hey ..
                  Check out the following link:

                  http://stackoverflow.com/questions/3627941/global-variable-within-multiple-files

                  Be Cute

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Wrong pattern to use in this case.

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

                    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