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. Project Management with subprojects: Accessing classes from another project
Qt 6.11 is out! See what's new in the release blog

Project Management with subprojects: Accessing classes from another project

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 557 Views
  • 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
    Smeeth
    wrote on last edited by Smeeth
    #1

    I am developing a large application that I wish to separate into 3 sub projects for organization and testing's sake; a model, a view, and a controller to act as a middle class between the two.

    Here is the structure I have currently:

    /Project
    | Project.pro
    |--- MODEL
    |    |--- MODEL.pro
    |    `--- ...source files
    |--- VIEW
    |    |--- VIEW.pro
    |    `--- ... source files
    |--- CONTROLLER
    |    |--- CONTROLLER.pro
    |    `--- ...source files
    

    My Project.pro looks like this

    TEMPLATE = subdirs
    
    SUBDIRS += \
        VIEW \
        CONTROLLER \
        MODEL
    
    # where to find the sub projects
    VIEW.subdir = VIEW
    MODEL.subdir = MODEL
    CONTROLLER.subdir = CONTROLLER
    
    # what subproject depends on others
    CONTROLLER.depends = VIEW MODEL
    

    I have a class MainWindow in VIEW. How can I add a reference to it in my CONTROLLER project so that I can use this MainWindow class in, for instance, the main.cpp in CONTROLLER?

    aha_1980A 1 Reply Last reply
    0
    • S Smeeth

      I am developing a large application that I wish to separate into 3 sub projects for organization and testing's sake; a model, a view, and a controller to act as a middle class between the two.

      Here is the structure I have currently:

      /Project
      | Project.pro
      |--- MODEL
      |    |--- MODEL.pro
      |    `--- ...source files
      |--- VIEW
      |    |--- VIEW.pro
      |    `--- ... source files
      |--- CONTROLLER
      |    |--- CONTROLLER.pro
      |    `--- ...source files
      

      My Project.pro looks like this

      TEMPLATE = subdirs
      
      SUBDIRS += \
          VIEW \
          CONTROLLER \
          MODEL
      
      # where to find the sub projects
      VIEW.subdir = VIEW
      MODEL.subdir = MODEL
      CONTROLLER.subdir = CONTROLLER
      
      # what subproject depends on others
      CONTROLLER.depends = VIEW MODEL
      

      I have a class MainWindow in VIEW. How can I add a reference to it in my CONTROLLER project so that I can use this MainWindow class in, for instance, the main.cpp in CONTROLLER?

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

      Hi @Smeeth,

      first of all, you don't need these lines if you have a subdir/subdir.pro structure:

      VIEW.subdir = VIEW
      MODEL.subdir = MODEL
      CONTROLLER.subdir = CONTROLLER

      How can I add a reference to it in my CONTROLLER project so that I can use this MainWindow class in, for instance, the main.cpp in CONTROLLER?

      Usually, each subproject generates a shared/static library or executable. So you would include the header file and link against the final library.

      So your first choice would be, which of these projects generate libraries and which one the final exe? That also enforces the .depends line (the exe cannot be build before the libs).

      Regards

      Qt has to stay free or it will die.

      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