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:
- The user is presented with text values and can explore further if they want to.
- The user clicks
Qt::PushButton
and the next cell is populated with aQt::ComboBox
containing other possible values to choose from. - 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 aQt::StandardItem
) - Then the checkbox can be checked.
- After selecting the rows the user wants, a
Qt::PushButton
located outside of theQt::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 appropriateComboBox
.
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>'