Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. When to start a new .cpp .h .ui
Forum Update on Monday, May 27th 2025

When to start a new .cpp .h .ui

Scheduled Pinned Locked Moved Solved Installation and Deployment
newbiefile structure
6 Posts 4 Posters 545 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
    Seabird
    wrote on 26 Apr 2022, 12:29 last edited by
    #1

    Maybe a very basic question but I see so many tutorials based on just one function I am a little lost how to combine it all.

    My main.cpp will have a nice top menu bar (file/edit/about etc)
    Now inside this window I want to create a tabbed view. Easily done. But should I just create that in the main window.ui?
    In each tab there is a different content
    -tab 1 tableview from a database (different cpp?)
    -tab 2 number overview from a database query etc
    -tab 3 settings (store in a .ini/conf file)

    Database connection setting: different cpp?

    J A 2 Replies Last reply 26 Apr 2022, 12:33
    0
    • S Seabird
      26 Apr 2022, 12:29

      Maybe a very basic question but I see so many tutorials based on just one function I am a little lost how to combine it all.

      My main.cpp will have a nice top menu bar (file/edit/about etc)
      Now inside this window I want to create a tabbed view. Easily done. But should I just create that in the main window.ui?
      In each tab there is a different content
      -tab 1 tableview from a database (different cpp?)
      -tab 2 number overview from a database query etc
      -tab 3 settings (store in a .ini/conf file)

      Database connection setting: different cpp?

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 26 Apr 2022, 12:33 last edited by
      #2

      @Seabird That's really up to you,

      I've seen "Applications" where everything was in a 10k+ main.cpp

      • was it readable? no
      • did I throw up a little bit, when I saw it? yes, yes I did

      As a general rule of thumb:
      If you think: "Should I make this a separate class/file?" Than do it :D


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      J 1 Reply Last reply 26 Apr 2022, 12:43
      3
      • J J.Hilk
        26 Apr 2022, 12:33

        @Seabird That's really up to you,

        I've seen "Applications" where everything was in a 10k+ main.cpp

        • was it readable? no
        • did I throw up a little bit, when I saw it? yes, yes I did

        As a general rule of thumb:
        If you think: "Should I make this a separate class/file?" Than do it :D

        J Online
        J Online
        JonB
        wrote on 26 Apr 2022, 12:43 last edited by JonB
        #3

        @J-Hilk said in When to start a new .cpp .h .ui:

        where everything was in a 10k+ main.cpp

        I know a user on this forum whose file is a lot bigger than this.... :)

        @Seabird
        Each of those tab contents sounds like a separate class/.ui file to me. Don't forget you can design a widget in its own designer file/.ui file/.cpp/.h file, and then e.g. use that at runtime to create the desired pages for the tabs.

        1 Reply Last reply
        0
        • S Seabird
          26 Apr 2022, 12:29

          Maybe a very basic question but I see so many tutorials based on just one function I am a little lost how to combine it all.

          My main.cpp will have a nice top menu bar (file/edit/about etc)
          Now inside this window I want to create a tabbed view. Easily done. But should I just create that in the main window.ui?
          In each tab there is a different content
          -tab 1 tableview from a database (different cpp?)
          -tab 2 number overview from a database query etc
          -tab 3 settings (store in a .ini/conf file)

          Database connection setting: different cpp?

          A Offline
          A Offline
          artwaw
          wrote on 26 Apr 2022, 12:45 last edited by
          #4

          @Seabird As @J-Hilk said.

          My rule of thumb is: can I make this bit of a code a separate, functional entity? If yes, then away it goes to a separate class.
          With anything requiring UI file it is no brainer though.

          For more information please re-read.

          Kind Regards,
          Artur

          J 1 Reply Last reply 26 Apr 2022, 12:48
          0
          • A artwaw
            26 Apr 2022, 12:45

            @Seabird As @J-Hilk said.

            My rule of thumb is: can I make this bit of a code a separate, functional entity? If yes, then away it goes to a separate class.
            With anything requiring UI file it is no brainer though.

            J Online
            J Online
            JonB
            wrote on 26 Apr 2022, 12:48 last edited by JonB
            #5

            @artwaw said in When to start a new .cpp .h .ui:

            My rule of thumb is: can I make this bit of a code a separate, functional entity? If yes, then away it goes to a separate class.

            The only thing I would say is. Some people create loads of little classes. And some people insist each class go in its own source file. Personally I find that "tiring" at the editing phase, having to swap between too many small classes/files. Not that yours isn't a reasonable rule, just one may not wish to take it too far down. There is a balance between classes/files which are too large and those which are too small.

            A 1 Reply Last reply 26 Apr 2022, 13:15
            0
            • J JonB
              26 Apr 2022, 12:48

              @artwaw said in When to start a new .cpp .h .ui:

              My rule of thumb is: can I make this bit of a code a separate, functional entity? If yes, then away it goes to a separate class.

              The only thing I would say is. Some people create loads of little classes. And some people insist each class go in its own source file. Personally I find that "tiring" at the editing phase, having to swap between too many small classes/files. Not that yours isn't a reasonable rule, just one may not wish to take it too far down. There is a balance between classes/files which are too large and those which are too small.

              A Offline
              A Offline
              artwaw
              wrote on 26 Apr 2022, 13:15 last edited by
              #6

              @JonB Of course. Hence the "functional" (from "functionality") part. In my workflow it helps, yours (and others) mileage might vary.

              For more information please re-read.

              Kind Regards,
              Artur

              1 Reply Last reply
              1

              6/6

              26 Apr 2022, 13:15

              • Login

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