Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Split header files
Qt 6.12 LTS is out! See what's new in the release blog

Split header files

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 623 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
    Stefanoxjx
    wrote on last edited by
    #1

    Hi, I would like to ask what is the better way to split header file?
    I've a class with many QStringList and Enum very long.
    This situation makes working in this file difficult and I would like to split in some specific files.
    At the moment I've created simple headers file and included in code like this:

    #include <QObject>
    #include <QWidget>
    
    class MyClass : public QWidget
    {
        Q_OBJECT
    
    #include "file1.h"
    #include "file2.h"
    #include "file3.h"
    
    public:
        explicit MyClass(QWidget *parent = nullptr);
    ...
    

    I know that it isn't a good practice but at the moment to make my life easier I did so.
    I thought maybe the correct way to do this can be create a new class (only header) and inherit this in my class.
    But I've a doubt that this too isn't a correct way.
    Can you suggest me what can be the correct method to do this?
    Thanks.

    jsulmJ 1 Reply Last reply
    0
    • S Stefanoxjx

      Hi, I would like to ask what is the better way to split header file?
      I've a class with many QStringList and Enum very long.
      This situation makes working in this file difficult and I would like to split in some specific files.
      At the moment I've created simple headers file and included in code like this:

      #include <QObject>
      #include <QWidget>
      
      class MyClass : public QWidget
      {
          Q_OBJECT
      
      #include "file1.h"
      #include "file2.h"
      #include "file3.h"
      
      public:
          explicit MyClass(QWidget *parent = nullptr);
      ...
      

      I know that it isn't a good practice but at the moment to make my life easier I did so.
      I thought maybe the correct way to do this can be create a new class (only header) and inherit this in my class.
      But I've a doubt that this too isn't a correct way.
      Can you suggest me what can be the correct method to do this?
      Thanks.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Stefanoxjx Hard to say without knowing what this class is doing.
      You should think about your architecture and design. Inheritance and composition can also help to make classes smaller.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      1
      • jsulmJ jsulm

        @Stefanoxjx Hard to say without knowing what this class is doing.
        You should think about your architecture and design. Inheritance and composition can also help to make classes smaller.

        S Offline
        S Offline
        Stefanoxjx
        wrote on last edited by Stefanoxjx
        #3

        @jsulm So you confirm that creating smal classes with only header files and inherithing them is the better way?

        jsulmJ 1 Reply Last reply
        0
        • S Stefanoxjx

          @jsulm So you confirm that creating smal classes with only header files and inherithing them is the better way?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Stefanoxjx It really depends. Besides inheritance there is also composition. What is better depends on the use case.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          1
          • jsulmJ jsulm

            @Stefanoxjx It really depends. Besides inheritance there is also composition. What is better depends on the use case.

            S Offline
            S Offline
            Stefanoxjx
            wrote on last edited by
            #5

            @jsulm Many thanks for your help :)

            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
            • Unsolved