Qt-question: How to react on a click on a table-cell?

Hi,
I want to achieve that if someone clicks on a cell in a Qt::Table
something happens. This is my code:

#!/usr/bin/env ruby
require 'Qt'

class MyWidget < Qt::Widget
        slots 'but_clie()'
       
        def initialize(parent=nil)
                super(parent)
                @table = Qt::Table.new(10,10,self)
                connect(@table,SIGNAL('clicked()'),self,SLOT('but_clie
()'))
        end

        def but_clie
                puts "clicked"
        end
end

app = Qt::Application.new(ARGV)
mw = MyWidget.new
app.setMainWidget(mw)
mw.show
app.exec()
# done

But If I start the app I always get this error:
QObject::connect: No such signal Qt::Table::clicked()
QObject::connect: (sender name: 'unnamed')
QObject::connect: (receiver name: 'unnamed')

But the Qt3 doc tells me that it definitivly has the signal clicked() ?

What am I doing wrong here?

greets

Alle Sunday 02 March 2008, Adna rim ha scritto:

Hi,
I want to achieve that if someone clicks on a cell in a Qt::Table
something happens. This is my code:

#!/usr/bin/env ruby
require 'Qt'

class MyWidget < Qt::Widget
        slots 'but_clie()'

        def initialize(parent=nil)
                super(parent)
                @table = Qt::Table.new(10,10,self)
                connect(@table,SIGNAL('clicked()'),self,SLOT('but_clie
()'))
        end

        def but_clie
                puts "clicked"
        end
end

app = Qt::Application.new(ARGV)
mw = MyWidget.new
app.setMainWidget(mw)
mw.show
app.exec()
# done

But If I start the app I always get this error:
QObject::connect: No such signal Qt::Table::clicked()
QObject::connect: (sender name: 'unnamed')
QObject::connect: (receiver name: 'unnamed')

But the Qt3 doc tells me that it definitivly has the signal clicked() ?

What am I doing wrong here?

greets

If you look at the documentation for QTable, you'll see that it has indeed a
clicked(), but that it takes four parameters (row, col, button and mousePos).
So, the correct way to connect signal and slot is:

connect(@table, SIGNAL('clicked(int, int, int, QPoint&'), self,
  SLOT('but_clie()'))

Note that, even if the code above works, your slot won't receive none of the
four parameters. If you want to receive them, you should declare the slot as:

slots 'but_clie(int,int,int,QPoint&)'

and connect it with

connect(@table, SIGNAL('clicked(int, int, int, QPoint&'), self,
  SLOT('but_clie(int,int,int,QPoint&)'))

Often, when qtruby says there's not a method with a certain name, the truth is
that such a method exists, but it takes different parameters from the ones you
used.

Disclaimer: all this code hasn't been tested, because I'm not using Qt3
anymore.

I hope this helps

Stefano

Thanks for your answer and I did like you suggested but the error stays
the same, also if I put 4 variables in the signal.

greets

Alle Sunday 02 March 2008, Adna rim ha scritto:

Thanks for your answer and I did like you suggested but the error stays
the same, also if I put 4 variables in the signal.

greets

Sorry, I should have read the documentation more carefully. In my previous
post, you should replace

QPoint&

with

const QPoint&

because the actual signature of signal is:

int, int, int, const QPoint&

Stefano

Many thanks now it works perfectly :slight_smile:

greets