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 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.HilkJ artwawA 2 Replies Last reply
    0
    • S Seabird

      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.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on 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.

      JonBJ 1 Reply Last reply
      3
      • J.HilkJ J.Hilk

        @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

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on 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

          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?

          artwawA Offline
          artwawA Offline
          artwaw
          wrote on 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

          JonBJ 1 Reply Last reply
          0
          • artwawA artwaw

            @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.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on 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.

            artwawA 1 Reply Last reply
            0
            • JonBJ JonB

              @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.

              artwawA Offline
              artwawA Offline
              artwaw
              wrote on 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

              • Login

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