[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

Adna rim

3/2/2008 1:10:00 PM

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
4 Answers

Stefano Crocco

3/2/2008 1:27:00 PM

0

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

Adna rim

3/2/2008 1:40:00 PM

0

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

Stefano Crocco

3/2/2008 2:05:00 PM

0

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


Adna rim

3/2/2008 2:13:00 PM

0

Many thanks now it works perfectly :)

greets