SMOKE copy constructor problem
Richard Dale <[email protected]>
| Newsgroups | gmane.comp.kde.devel.perl,gmane.comp.kde.devel.bindings |
|---|---|
| Organization | Lost Highway |
| Message-ID | <[email protected]> |
I've had a problem with copy constructors with SMOKE. A copy constructor is
added for a Smoke class, even if the original C++ class didn't have one,
according to the following rule:
# If the class has no explicit copy constructor, and it can be copied,
# generate the copy constructor.
if ( !$classNode->{HasCopyConstructor}
&& $classNode->{CanBeCopied}
&& $classNode->{CanBeInstanciated} ) {
...
}
QListViewItem and KListViewItem have these additional constructors, but it
causes problems with ruby. I tried a QListViewItem example in PerlQt and that
worked ok, even though it found ambiguous method calls:
perl listview.pm
Ambiguous method call for :
QListViewItem::QListViewItem(QListViewItem)
Candidates are:
QListViewItem* QListViewItem::QListViewItem(QListViewItem*)
QListViewItem* QListViewItem::QListViewItem(const QListViewItem&)
Taking first one...
In ruby it fails and won't run because ambiguous calls are an error.
But both ruby and perl won't work with KListViewItems because the copy
constructor expects a 'const KListViewItem&' argument, while all the normal
constructors expect a parent QListViewItem to be passed. So the copy
constructor will get called instead of the correct one that expects a parent.
I would expect this PerlKDE code won't work:
my $kListView = KDE::ListView(this, "");
$kListView->addColumn("Content");
$kListView->setSorting(-1);
my $item0 = KDE::ListViewItem($kListView);
$item0->setText(0, "Root");
$item0->setOpen(1);
my $item3 = KDE::ListViewItem($item0);
$item3->setText(0, "Level 1, Third Item");
my $item1 = KDE::ListViewItem($item0);
$item1->setText(0, "Level 1, First Item");
my $item2 = KDE::ListViewItem($item0, $item1);
$item2->setText(0, "Level 1, Second Item");
I haven't got PerlKDE setup, so I can't try it out and confirm, but I think
these autogenerated copy constructors should be removed from the Smoke
runtime as they're more trouble than they're worth.
-- Richard
_______________________________________________
Kde-perl mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kde-perl
listview.pm
(text/x-perl, 179 B)
#!/usr/bin/perl -w use strict; use Qt; use MyListView; my $a = Qt::Application(\@ARGV); my $listview = MyListView; $a->setMainWidget($listview); $listview->show; exit $a->exec;
MyListView.pm
(text/x-perl, 846 B)
package MyListView;
use strict;
use Qt;
use Qt::isa qw(Qt::Widget);
use Qt::debug;
sub NEW {
shift->SUPER::NEW(@_);
my $topLayout = Qt::VBoxLayout( this );
$topLayout->setAutoAdd( 1 );
my $kListView = Qt::ListView(this, "");
$kListView->addColumn("Content");
# kListView.setFullWidth(true)
$kListView->setSorting(-1);
my $item0 = Qt::ListViewItem($kListView);
$item0->setText(0, "Root");
$item0->setOpen(1);
my $item3 = Qt::ListViewItem($item0);
$item3->setText(0, "Level 1, Third Item");
my $item1 = Qt::ListViewItem($item0);
$item1->setText(0, "Level 1, First Item");
my $item2 = Qt::ListViewItem($item0, $item1);
$item2->setText(0, "Level 1, Second Item");
}
1;