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



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

    Any other suggestion?



  • 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();
    ......
    };


  • Lifetime Qt Champion

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.