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 7788995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:09:20+00:00 2026-06-01T21:09:20+00:00

I have a QMainWindow with two QTableViews on it. Each QTableView has its own

  • 0

I have a QMainWindow with two QTableViewson it. Each QTableView has its own QSqlRelationalTableModel. I am using OnManualSubmit as the edit strategy for both models. Both models hit the same database, and are populated using setTable (each hits a different table), followed by select().

The model for the second table is set up with appropriate calls to setRelation to link it to the table used to populate the first model. On the second (child) view, I call view->setItemDelegate(new QSqlRelationalDelegate(view));

Everything seems to work great: data that appears in the first view is listed in a drop-down in the appropriate field of the second view.

My issue: when I add, edit, or delete a record to the first (parent) view and save it to the database, how should I refresh the second view so that the drop-down is accurate?

There may be unsaved edits in the second (child) view, and I don’t want to lose those, nor do I want to save them yet. I just want the drop-down list to be updated appropriately.

I tried child_model->relationModel(fk_col)->select(); and that works, but child_model->relationModel(fk_col)->columnCount(); indicates that the select is operating on all the fields of the parent table, which seems like unnecessary pessimization.

This is my first attempt using <QtSql> and QTableView so I may be missing something fundamental. Maybe there is a way to use the same model for both views, and the refresh happens automatically? What is the appropriate way for child view drop-downs to be refreshed?

  • 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-01T21:09:22+00:00Added an answer on June 1, 2026 at 9:09 pm

    The query executed by QSqlRelationalTableModel doesn’t contains the foreign keys anymore.

    For example with this db structure:

    CREATE TABLE countries (id, name);
    CREATE TABLE cities(id, name, id_country);
    

    The query would look like this:

    SELECT id, name, country_name FROM cities 
        LEFT JOIN countries ON id_country = countries.id;
    

    Which means, the query has to be re-executed for the table to be updated, if the joined table changes.

    To refresh automatically, I guess you would have:

    • to use regular QSqlTableModel to keep the actual foreign keys in the model,
    • to write a QAbstractItemDelegate class to display the mapped value and to create the QComboBox editor.
    • to trigger a repaint of the mapped column area on the view whenever the first model changes.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two targets in my Xcode 4.3 project. Each target has its own
i have a QMainWindow. It has this parameters: this->setWindowFlags(Qt::Tool); this->setFocusPolicy(Qt::StrongFocus); this->setAttribute(Qt::WA_QuitOnClose,true); After showEvent calles
I have a QMainWindow which spawns a few wizards. The QMainWindow has a QFrame
I have two custom widgets (two classes based on QtGui.QWidget). In __init__ of QtGui.QMainWindow
I have a UI with nested WPF UserControls each with their own view models.
I'm creating my own UserControl and I have two different DataTemplates under the UserControl.Resources
I have two projects, a resourcelibrary which holds a xaml file that simply has
I have set up a simple control with three rectangles, each of which has
I would like to have a QMainWindow that can change it's look at runtime,
I have an inactive QMainWindow with a QTabWidget as CentralWidget which holds multiple QPlainTextEdits

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.