Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9019389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:45:56+00:00 2026-06-16T04:45:56+00:00

I am mostly a Python/Django developer, so I might be a little off in

  • 0

I am mostly a Python/Django developer, so I might be a little off in the terminology, so I can’t find answer to this question:

How/where should I define custom model logic in C++/Qt?

Let say I have table Users with column date_birth and I want to add method getAge(), which simply calculate user’s age.

Where would I put this? Creating a subclass of QSqlRecord seems to me appropriate, but I haven’t found any references to this approach.

Second: Are there any conventions for subclassing QSql(Relational)?TableModel?

I’ve found similar snippet in many examples:

QSqlTableModel *model = new QSqlTableModel(parentObject, database);
model->setTable("employee");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select();
model->setHeaderData(0, Qt::Horizontal, tr("Name"));
model->setHeaderData(1, Qt::Horizontal, tr("Salary"));

but it seems redundant to define it everywhere I need it. Is it common to create subclasses such as UserTableModel and call all these methods in it’s constructor? Again, I haven’t found any references to it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:45:57+00:00Added an answer on June 16, 2026 at 4:45 am

    What you are trying to achieve is an objets/relational mapping.

    So do it, it’s better not to make objects inherit from any SQL classes (in any object language)

    You may create 2 classes: one for your “employee” and a factory object which will create this object by dealing with SQL ones:

    ObjectsFactory *factory = new ObjectsFactory();
    Employee e = factory->getEmployee(2423);
    int age = e->getAge();
    

    With this kind of solution, your Employee class won’t depend on SQL classes. You can even chose to create handlers depending on any storage model.

    ObjectFactory *factory = new ObjectsFactory(new SQLHandler);
    

    or (more convenient for testing)

    ObjectFactory *factory = new ObjectsFactory(new FileHandler);
    
    ObjectFactory *factory = new ObjectsFactory(new MemoryHandler);
    

    I suggest you have a look at Data Access Object pattern

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I mostly develop using C#, but I think this question might be suitable for
I'm moving from a PHP background into Django development via python, mostly for the
I'm talking mostly about Python here, but I suppose this probably holds for most
I am using Python (SimPy package mostly, but it is irrelevant to the question
This is a simple question about how Python handles data and variables. I've done
I posted this basic question before, but didn't get an answer I could work
I mostly spend time on Python/Django and Objective-C/CocoaTouch and js/jQuery in the course of
I have some python modules containing mostly functions and a few classes. Each one
I am new to Matplotlib and Python. I mostly use Matlab. Currently, I am
The title says it mostly. If I have an object in Python and want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.