0

EDIT

The problem was with something else so the trouble wasn't really Qt, still I don't know why this happened.

The thing was that in the method display_filesize @yt.get_filesize(row_id, format) I used Nokogiri to parse the XML. I don't know if the XML was corrupted (it was loaded from quvi), but it was definitely the culprit. After switching to XMLSimple everything works fine.

The code I used:

def get_filesize(video_id, format)
  video = @videos[video_id]

  if video.formats[format].empty?
    to_parse = `quvi --xml --format #{format} #{video.player_url}`
    parsed = Nokogiri.parse(to_parse)
    video.formats[format] = { :size => parsed.at('length_bytes').text, 
                              :url => parsed.at('link').at('url').text }
  end
  video.formats[format][:size]
end

Now I use something like this:

def get_filesize(video_id, format)
  video = @videos[video_id]

  if video.formats[format].empty?
    to_parse = `quvi --xml --format #{format} #{video.player_url}`
    parsed = XmlSimple.xml_in(to_parse, {'KeyAttr' => 'name'})

    video.formats[format] = { :size => parsed['link'][0]['length_bytes'][0],
                              :url => URI.decode(parsed['link'][0]['url'][0]) }
  end

  video.formats[format][:size]
end

It works beautifully. Still, I don't know why it crashed. This is the real question.


OLD QUESTION

I have a Qt::TableView that contains Qt::StandardItemModel. A row in the model consists of text, Qt::PushButton, checkbox and Qt::ComboBox. It works like this:

  1. The user is presented with text values and can explore further if they want to.
  2. The user clicks Qt::PushButton and the next cell is populated with a Qt::ComboBox containing other possible values to choose from.
  3. If the user chooses an option from Qt::ComboBox, magic happens, objects get created, hashes populated and the cell on the right gets populated with appropriate text (through a Qt::StandardItem)
  4. Then the checkbox can be checked.
  5. After selecting the rows the user wants, a Qt::PushButton located outside of the Qt::TableView can be clicked. It then iterates through the model, tests if the checkbox is selected and should it be, tries to access the value in the appropriate ComboBox.

The problem is, when I insert code that tries to access the Qt::ComboBox, I can't insert the Qt::StandardItem, because I can't get the model, because Qt::TableView.model returns NilClass (at some point).

I don't know why and how this happens. It's a random thing, sometimes the value of Qt::ComboBox can be changed a couple times, sometimes the first try ends with an error.

Here is how I create the Qt::StandardItem:

def display_filesize
  row_id = row_id_from_object_name(sender.objectName)
  format = sender.currentText

  filesize = @yt.get_filesize(row_id, format) # get the text
  filesize_item = Qt::StandardItem.new("#{(filesize.to_i/1024/1024)} MB ")

  # @tc simply stores the indexes of columns so I can access them easily
  @ui.tableView.model.setItem(row_id, @tc[:filesize], filesize_item) 
end

And here is how I try to access the Qt::ComboBox value:

model = @ui.tableView.model

checked = model.rowCount.times.map do |i|
  if model.item(i, @tc[:check]).checkState == Qt::Checked
    # if I remove the following two lines it works...
    index = model.index(i, @tc[:formats])
    format = @ui.tableView.indexWidget(index).currentText
    @yt.videos[i][format]
  end
end

And this is the error I am trying to get rid of:

searcher.rb:86:in `display_filesize': undefined method `index' for nil:NilClass (NoMethodError)
from /var/lib/gems/1.9.1/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:469:in `qt_metacall'
from /var/lib/gems/1.9.1/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:469:in `method_missing'
from /var/lib/gems/1.9.1/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:469:in `exec'
  from qutub-player.rb:17:in `<main>'
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
k_ly
  • 1
  • 1
  • You don't show any XML, so how can we even try to answer your question? Nokogiri makes it easy to tell if the XML has a problem; Simply check `parsed.errors` after parsing and see if it's empty or has content. Use `Nokogiri.XML(...)` to parse XML. Relying on `parsed = Nokogiri.parse(to_parse)` can result in parsing as HTML if Nokogiri finds a "html" tag at the top of the document. That'll result in bad results as you search. – the Tin Man Jun 17 '13 at 01:40
  • It is not very related, but I've released quvi bindings for ruby, and it is possible to cut the corner, and do not use XML. https://rubygems.org/gems/quvi – avsej Apr 21 '14 at 04:45

0 Answers0