[Kde-bindings] Qt::StandardItemModel#item_prototype= causes crashe in qtruby
Stefano Crocco
stefano.crocco at alice.it
Tue Apr 14 18:56:49 UTC 2009
On Tuesday 14 April 2009, Richard Dale wrote:
> |On Friday 10 April 2009 08:58:37 Stefano Crocco wrote:
> |> Using Qt::StandardItemModel#item_prototype= and
> |> Qt::StandardItemModel#horizontal_header= causes ruby to crash. Here's
> |> the code causing the crash:
> |>
> |> require 'Qt4'
> |>
> |> app = Qt::Application.new []
> |> m = Qt::StandardItemModel.new
> |> proto = Qt::StandardItem.new ''
> |> proto.flags = Qt::ItemIsEnabled
> |> m.set_item_prototype proto
> |> m.horizontal_header_labels = %w[x y]
> |> app.exec
> |>
> |> If I comment out the call to horizontal_header_labels=, everything works
> |> correctly.
> |>
> |The crash is because you need to implement the clone() method in your
> |Qt::StandardItem:
> |
> |require 'Qt4'
> |
> |class MyStandardItem < Qt::StandardItem
> | def clone
> | return MyStandardItem.new('')
> | end
> |end
> |
> |app = Qt::Application.new []
> |m = Qt::StandardItemModel.new
> |proto = MyStandardItem.new ''
> |proto.flags = Qt::ItemIsEnabled
> |m.set_item_prototype proto
> |m.horizontal_header_labels = %w[x y]
> |app.exec
> |
> |-- Richard
> |
Sorry, I completely misunderstood what the prototype does and how it should be
used. However, I still can't understand why my program crashes. After all, my
prototype was an instance of QStandardItem, which does have a clone method. So
why should it crash? Also, I tried writing the same program in C++, and it
doesn't crash (of course, as I now understand, setting the prototype this way
doesn't do anything, but now this is beside the point). Here's the C++
version:
#include <QApplication>
#include <QStandardItemModel>
#include <QStringList>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QStandardItemModel * m = new QStandardItemModel;
QStandardItem * proto = new QStandardItem;
proto->setFlags(Qt::ItemIsEnabled);
m -> setItemPrototype(proto);
QStringList headers;
headers << "x" << "y";
m->setHorizontalHeaderLabels(headers);
return app.exec();
}
Am I missing something else?
Stefano
More information about the Kde-bindings
mailing list