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

**URL:** <https://www.ruby-forum.com/t/qt-question-how-to-react-on-a-click-on-a-table-cell/130720>\
**Category:** Ruby\
**Created:** [March 2, 2008, 2:15pm UTC](https://www.ruby-forum.com/t/qt-question-how-to-react-on-a-click-on-a-table-cell/130720 "2008-03-02T14:15:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adna\_rim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e47c2d/32.png) [@Adna\_rim](https://www.ruby-forum.com/u/Adna_rim)\
**Post date:** [March 2, 2008, 2:15pm UTC](https://www.ruby-forum.com/t/qt-question-how-to-react-on-a-click-on-a-table-cell/130720/1 "2008-03-02T14:15:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Adna\_rim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e47c2d/32.png) [@Adna\_rim](https://www.ruby-forum.com/u/Adna_rim)\
**Post date:** [March 2, 2008, 2:28pm UTC](https://www.ruby-forum.com/t/qt-question-how-to-react-on-a-click-on-a-table-cell/130720/2 "2008-03-02T14:28:22Z")

</div>

Alle Sunday 02 March 2008, Adna rim ha scritto:

> ```
> def initialize(parent=nil)
> 
> ```
> 
> 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

---

<div class="post-metadata">

**Author:** ![Adna\_rim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e47c2d/32.png) [@Adna\_rim](https://www.ruby-forum.com/u/Adna_rim)\
**Post date:** [March 2, 2008, 2:40pm UTC](https://www.ruby-forum.com/t/qt-question-how-to-react-on-a-click-on-a-table-cell/130720/3 "2008-03-02T14:40:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Adna\_rim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e47c2d/32.png) [@Adna\_rim](https://www.ruby-forum.com/u/Adna_rim)\
**Post date:** [March 2, 2008, 3:12pm UTC](https://www.ruby-forum.com/t/qt-question-how-to-react-on-a-click-on-a-table-cell/130720/4 "2008-03-02T15:12:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Adna\_rim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e47c2d/32.png) [@Adna\_rim](https://www.ruby-forum.com/u/Adna_rim)\
**Post date:** [March 2, 2008, 3:15pm UTC](https://www.ruby-forum.com/t/qt-question-how-to-react-on-a-click-on-a-table-cell/130720/5 "2008-03-02T15:15:37Z")

</div>

Many thanks now it works perfectly 🙂

greets
