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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:23:12+00:00 2026-05-22T17:23:12+00:00

I have found example how to use QTableView : http://doc.trolltech.com/4.5/sql-querymodel.html It works fine. Data

  • 0

I have found example how to use QTableView:
http://doc.trolltech.com/4.5/sql-querymodel.html
It works fine. Data is shown in QTableView.

But QTableView in this example is created dynamically in main.cpp file.
In my application I have main form and I added QTableView in designer. I try to populate this QTableView in constructor but without result:

MainApplication::MainApplication(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainApplication)
{
    ui->setupUi(this);


    QMap<QString, double> currencyMap;
        currencyMap.insert("AUD", 1.3259);
        currencyMap.insert("CHF", 1.2970);
        currencyMap.insert("CZK", 24.510);


        CurrencyModel currencyModel;
        currencyModel.setCurrencyMap(currencyMap);

      ui->tableView_currencies->setModel(&currencyModel);
      ui->tableView_currencies->setAlternatingRowColors(true);

      ui->tableView_currencies->setWindowTitle(QObject::tr("Currencies"));
      ui->tableView_currencies->show();

}

QTableView is showing on main form empty, only columns and rows headers are visible. And data is not shown.

Does anybody know of a site with examples where components like QTableView, QListView are added in designer? In trolltech (nokia) tutorials all components are created dynamically.

  • 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-05-22T17:23:13+00:00Added an answer on May 22, 2026 at 5:23 pm

    The model is no longer valid after the constructor is executed!
    You create a local object currencyModel that will be destroyed when it goes out of scope (at the end of the c’tor), but pass a pointer to it as the model for the table view!
    The table view doesn’t deep-copy the given model, and in fact doesn’t even take ownership of the passed pointer:

    The view does not take ownership of the model unless it is the model’s parent object because the view may be shared between many different views.
    (QTableView doc)

    You should simply allocate the model no the heap (using new) and set the view as it’s parent object. in that way, the table view will also handle its deletion:

    CurrencyModel *currencyModel = new CurrencyModel(ui->tableView_currencies);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In stackoverflow.com I have found a question where a user was suggesting to use
I try to use Moose. It's great, when it works. However, I have found
I have done some research, and majority of the examples I have found use
I have found that my HTML is, to be honest, very clunky. Small, simple
By using Google I have found some nice snippets of example code for using
I am trying to use WPF printing from PowerShell. I have found a simple
I have found the following document at the Android dev site, which works for
Would the following be considered as private API use? After googling I have found
Possible References I have found a similar problem: Refreshing a SQL database connection which
I know this seems like I should have immediately found the one example out

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.