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

A

Adna rim

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
 
S

Stefano Crocco

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
 
A

Adna rim

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
 
S

Stefano Crocco

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top