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. I got 7 different features on my main window of my application, how to seperate my code for each feature?
Qt 6.11 is out! See what's new in the release blog

I got 7 different features on my main window of my application, how to seperate my code for each feature?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.9k 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.
  • L Offline
    L Offline
    Leon
    wrote on last edited by
    #1

    So i have a main window with 7 different features, so mainwindow.cpp is filled with code from every feature. But this makes the code unreadable (like when u want to know how one of the feature is made you must search trought everything), and i was thinking to seperate the code somehow.

    • 1st thing i thought was to use classes, but when i need for example a timer that has been declared on another class i will need to use signals etc everytime in order for the classes to communicate.

    • 2nd was seperate cpp files, but its the same

    • 3rd and the most simple was to use acci letters something like:
      "http://patorjk.com/software/taag/#p=display&f=Graffiti&t=Feature":http://patorjk.com/software/taag/#p=display&f=Graffiti&t=Feature

    Any other suggestion?

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Eng.MG
      wrote on last edited by
      #2

      you can separate your code in multiple header (.h) files..

      for example
      //in mainwindow.cpp :-
      #include MyTimer ;

      //in MyTimer.h
      class MyTimer : public Qtimer(......)
      {
      ...
      ....
      ......
      };

      if MyTimer needs something (a class, variable... etc) from other file you can just declare it and leave the definition where it is (supposing that it's already defined in where you're using class MyTimer)

      for example if MyTimer needs a class named class_1 you can write this in MyTimer.h file:-

      class class_1 ;

      class MyTimer : public Qttimer(......)
      {
      ...
      ....
      class_1 *object_1 = new class_1();
      ......
      };

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        The most straight forward (not saying it's easy) is to encapsulate each feature in it's own class so they might also become reusable.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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