Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. better design pattern

better design pattern

Scheduled Pinned Locked Moved Unsolved C++ Gurus
9 Posts 3 Posters 1.9k Views 2 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.
  • Thank YouT Offline
    Thank YouT Offline
    Thank You
    wrote on last edited by Thank You
    #1

    I want to know which type of design patter would you use and which would you think is best.

    IG it will be quite long but instead of making many different questions, I will be doing in one.

    Suppose, We will be using some database with some tables

    I will try to simplify as much as I can
    Let's Start

    User_Email Table:

    id name Email
    1 Cute Mute boi@email.com
    3 Hes Mos hey@email.com

    User_post Table:

    id post
    1 welcome
    1 dope

    Which approach would be best for connection of these data base and fetching all datas:
    Taking these in consideration:

    • Design Pattern
    • Code Readability
    • Maintenance
    • Memory Footprint
    • Faster
    • Folder Structure

    Let's suppose some scenario:

    • Name will be in drop-down menu in multiple widgets, lets say 10
    • User can post post and other data through different widgets. (Lets think that there are more than one 20 columns of data with separate insert , update and delete widget)

    How to cope with this situation? I will mention my way, and I am very pleased to get it's bad sides.

    Method 1:

    creating widgets like updateusername.h , updatepost.h , createpost.h, updateemail.h and so on for all
    And implementing them differently like:

    • Opening connection in main -> main.cpp or any other file that will execute at first
    • Getting connection and fetching same thing repeatedly over and over for multiple files.
      Suppose, we want to fill all emails in QComboBox in all of files,
      So creating fillEmail() in each file we have


    Method 2:

    • creating widgets like mentioned in method one
    • Creating Database Controller class for every table
      Like user_email.h
    class userEmail{
    public:
    void updateEmail(int id, QString newEmail);
    void updateName(int id, QString newName);
    QVector<QString> getAllEmail();
    QVector<QString> getAllName();
    private:
    int id;
    QString name;
    QString email;
    };
    

    and same for all tables and including that class in all file that we are gonna use this like
    updateemail.h

    #include"user_email.h"
    // all class declaration-----
    private:
    userEmail thisOne;
    
    // and in updateemail.cpp, use functions 
    

    If updatename.h is another file using this database, we include in same way and do rest of it.


    Method 3:

    Almost same as method 2,
    but creating all database controllers as SINGLETONS, (may be less memory footprints? 🤔)


    I can mostly think of these three patterns only.

    I would be happy to get links and study materials if you feel I am not that mature with any of idea.

    Ah!, It became quite long than expected.

    Let's make QT free or It will go forever

    TRUE AND FALSE <3

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

      Hi,

      Did you consider using QDataWidgetMapper ?

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

      Thank YouT 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        Did you consider using QDataWidgetMapper ?

        Thank YouT Offline
        Thank YouT Offline
        Thank You
        wrote on last edited by
        #3

        @SGaist
        Oh! Thank You, I will take a look on that.

        It would be much nicer to get comments about my methods and my thinkings too 😁

        Let's make QT free or It will go forever

        TRUE AND FALSE <3

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

          I would say a bit too complicated.

          You seem to be ready to store a lot of data in each of your widgets rather than take advantage of the model view approach.

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

          Thank YouT D 2 Replies Last reply
          0
          • SGaistS SGaist

            I would say a bit too complicated.

            You seem to be ready to store a lot of data in each of your widgets rather than take advantage of the model view approach.

            Thank YouT Offline
            Thank YouT Offline
            Thank You
            wrote on last edited by
            #5

            @SGaist
            Yes, I was waiting for something like this.
            I am not really making application but want to know how to cope with something like this. It was in my mind for long time so I asked about it.
            The last simple application I designed had these problem so I thought it would be much better to know about it before actually making another application

            Let's make QT free or It will go forever

            TRUE AND FALSE <3

            SGaistS 1 Reply Last reply
            0
            • SGaistS SGaist

              I would say a bit too complicated.

              You seem to be ready to store a lot of data in each of your widgets rather than take advantage of the model view approach.

              D Offline
              D Offline
              develop world
              wrote on last edited by
              #6

              Yes I am also eager to know about this question 😀😀

              1 Reply Last reply
              0
              • Thank YouT Thank You

                @SGaist
                Yes, I was waiting for something like this.
                I am not really making application but want to know how to cope with something like this. It was in my mind for long time so I asked about it.
                The last simple application I designed had these problem so I thought it would be much better to know about it before actually making another application

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                With a more detailed description about what your application will be about, it would be easier to discuss.

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

                Thank YouT 1 Reply Last reply
                0
                • SGaistS SGaist

                  With a more detailed description about what your application will be about, it would be easier to discuss.

                  Thank YouT Offline
                  Thank YouT Offline
                  Thank You
                  wrote on last edited by
                  #8

                  @SGaist
                  Oh ! It's been long since last time I was in this forum.
                  You can think this application as application where users can fetch/post/export/update/delete data which are stored in different tables in database.
                  Suppose let's say about all "fetching" here (getting list of datas and filling in combobox, auto filling datas in update pages, showing datas in tableviews and things like these)

                  I had mentioned methods in the previous post. I would like to get your views on which method is efficient than others and consume less resources.
                  Is it good to load all data in constructor in every pages or create a controller and use that in different pages as needed?
                  Next one is If I have database mentioned above "user_email" Should I create a database page with functions like getName(QString email), getEmail(QString name), updateName(QString previousname), getAllDetails(QString name), deleteData(QString name), getTotalCount(), insertData(name,email)
                  or should I implement these on specific widgets as needed in that widget.

                  These fetched data could be used in different widgets and filled in combo boxes and other widgets as needed.

                  I had created one application. That used to fetch all data in constructor and it makes application load time nearly 30 seconds on some low end computers. So I feel like I should load data only when the widget is opened/shown. Which approach of data loading should be used?

                  Let's make QT free or It will go forever

                  TRUE AND FALSE <3

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

                    When data loading is slow, lazy loading is used so it only impacts on use.

                    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