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. Where do I define a struct in order to be accessible to all my classes?
Forum Updated to NodeBB v4.3 + New Features

Where do I define a struct in order to be accessible to all my classes?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 484 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.
  • S Offline
    S Offline
    SlowerPhoton
    wrote on last edited by SlowerPhoton
    #1

    The files I have are the following:

    • myProject.pro
    • mainwindow.h
    • otherwindow.h
    • main.cpp
    • mainwindow.cpp
    • otherwindow.cpp
    • mainwindow.ui
    • otherwindow.ui

    In which one should I put the struct definition?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi, welcome to the forum.

      There are two things here - the declaration and an instance of that struct.
      The declaration should go in neither of these files. It should go into myawesomestruct.h, and get included in .cpp files you need it in.
      As for an instance of that struct - that depends on what that struct is and how it should be interacted with.

      It can be a global instance - declared as extern in a header and defined in its own .cpp file.
      It can be a member of a globally accessible instance of some class.
      It can be a dynamically added property on a globally accesible object (e.g. the application object).
      It can be a member passed as a parameter between other classes methods.
      It can be a member of a class which instance is passed around.
      ... <- enter 10 other options here

      It all depends on the purpose of that struct and intended usage pattern.

      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