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 a variable from one file , to another file
Qt 6.11 is out! See what's new in the release blog

Accessing a variable from one file , to another file

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 840 Views 2 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.
  • Swati777999S Offline
    Swati777999S Offline
    Swati777999
    wrote on last edited by Swati777999
    #1

    Hi All,

    I'm stuck at a point.

    I've a project myProject in which there custom libraries such as A,B,C,D,E.

    So myProject contains myProject.pro , A,B,C,D,E
    then the structure of A is A.pro , A1,A2,A3 where A1 has files like A1.pro, Headers(A11.h,A12.h,A13.h),Sources(A11.cpp,A12.cpp,A13.cpp)

    Same structure follows for B,C,D,E ....

    a1 is a member variable[private] of class A11 [available in A11.h], how can I access it in file D12.cpp?

    “ In order to be irreplaceable, one must always be different” – Coco Chanel

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

      Hi,

      Add proper accessors to your A11 class

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

      Swati777999S 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        Add proper accessors to your A11 class

        Swati777999S Offline
        Swati777999S Offline
        Swati777999
        wrote on last edited by
        #3

        @SGaist
        and a1 is a private member of A11.
        do you mean I've to follow inheritance? Is there any way other than inheritance and friend function?

        “ In order to be irreplaceable, one must always be different” – Coco Chanel

        JKSHJ 1 Reply Last reply
        0
        • Swati777999S Swati777999

          @SGaist
          and a1 is a private member of A11.
          do you mean I've to follow inheritance? Is there any way other than inheritance and friend function?

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @Swati777999 said in Accessing a variable from one file , to another file:

          do you mean I've to follow inheritance?

          No, @SGaist said "Add proper accessors to your A11 class". This means: add member functions to A11. It does not involve inheritance.

          Do you know what is a "member function" or a "class method"?

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          Swati777999S 1 Reply Last reply
          2
          • JKSHJ JKSH

            @Swati777999 said in Accessing a variable from one file , to another file:

            do you mean I've to follow inheritance?

            No, @SGaist said "Add proper accessors to your A11 class". This means: add member functions to A11. It does not involve inheritance.

            Do you know what is a "member function" or a "class method"?

            Swati777999S Offline
            Swati777999S Offline
            Swati777999
            wrote on last edited by Swati777999
            #5

            @JKSH Yes, I am acquainted with the member functions but how to apply the logic here?

            “ In order to be irreplaceable, one must always be different” – Coco Chanel

            JKSHJ 1 Reply Last reply
            0
            • Swati777999S Swati777999

              @JKSH Yes, I am acquainted with the member functions but how to apply the logic here?

              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by JKSH
              #6

              @Swati777999 said in Accessing a variable from one file , to another file:

              @JKSH Yes, I am acquainted with the member functions but how to apply the logic here?

              Write member functions that allow other classes to access private member variables.

              How do you usually use your member functions?

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              4

              • Login

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