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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:15:53+00:00 2026-05-31T17:15:53+00:00

I’ve been following this article to display ActiveRecord data in QtRuby. I’ve copied the

  • 0

I’ve been following this article to display ActiveRecord data in QtRuby. I’ve copied the BoatTableModel class from there(used my own code for the rest). In the article, BoatTableModel is defined to only support the Boat model, but except for the column definitions the code is quite generic. So, I’ve changed it so instead of having the columns defined there, I’ve made it take the columns from a column_names method, and define that methods in subclasses for each model.

Here is my code:

class QtArModel<Qt::AbstractTableModel
    def initialize(items)
        super()
        @items=items
    end

    def rowCount(parent=nil)
        @items.size
    end

    def columnCount(parent=nil)
        column_names.length
    end

    def data(index,role=Qt::DisplayRole)
        invalid=Qt::Variant.new
        return invalid unless role==Qt::DisplayRole or role==Qt::EditRole
        item=@items[index.row]
        return invalid if item.nil?

        v=item[column_names[index.column]]||""

        return Qt::Variant.new(v)
    end

    def headerData(section,orientation,role=Qt::DisplayRole)
        invalid=Qt::Variant.new
        return invalid unless role==Qt::DisplayRole

        v=case orientation
          when Qt::Horizontal
              column_names[section]
          else
              ""
          end
        return Qt::Variant.new(v.to_s)
    end

    def flags(index)
        return Qt::ItemIsEditable|super(index)
    end

    def setData(index,variant,role=Qt::EditRole)
        if index.valid? and role==Qt::EditRole
            s=variant.toString
            item=@items[index.row]
            if index.column.between?(0,column_names.length-1)
                item[column_names[index.column]]=s
            else
                raise "invalid column #{index.column}"
            end

            item.save

            emit dataChanged(index,index)
        else
            return false
        end
    end
end



class QtCoursesTableModel<QtArModel
    def column_names
        return [
            :number,
            :name,
            :tutor_name,
            :site,
            :active,
        ]
    end
end

class QtTasksTableModel<QtArModel
    def column_names
        return [
            :course,
            :ex_number,
            :received,
            :due,
            :description,
            :link,
            :completed,
            :file,
        ]
    end
end

Now, when I display one model(doesn’t matter which) – everything works just fine. However, when I display both models, each in it’s own Qt::TableView – only the first one is displayed, and the other table view is blank.

I’ve tried different ordering, and the table that gets to display it’s data is always the one which it’s Qt::TableView is created first – the order of the creating the Qt models does not matter. Also, when I create the model object for the first table, but don’t actually set it’s model property to it, the second table displays it’s data.

I’ve also tried to display the same model twice in two different table views – and it worked – for a split second, and then the second view’s data disappeared.

I’ve also tried to copy-paste the QtArModel, change it’s name, and make one of the models inherit from the copy. That did work – but it’s obviously a huge code duplication, so I would really like to avoid that.

Now, my guess is that something in QtArModel is defined as a class member instead of instance member, making both model instances share something they shouldn’t share. It has to be in QtArModel – because if it was higher in the inheritance tree, the problem would have remained when I’ve duplicated QtArModel. However, I can’t find anything in my QtArModel that’s class-scoped instead of instance-scoped.

What am I missing?

  • 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-31T17:15:54+00:00Added an answer on May 31, 2026 at 5:15 pm

    OK, I’ve managed to work this out. Apparently, the problem was not the inheritance, but the GC. Since the only connection to the models was from TableView’s model property – which is just a wrapper for C++ getter and setter – ruby thought it lost the reference to my models, and GC’d them.

    Solved by keeping the models in ruby variables.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,

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.