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

Discussion in 'Ruby' started by Adna rim, Mar 2, 2008.

  1. Adna rim

    Adna rim Guest

    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
     
    Adna rim, Mar 2, 2008
    #1
    1. Advertisements

  2. Alle Sunday 02 March 2008, Adna rim ha scritto:
    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
     
    Stefano Crocco, Mar 2, 2008
    #2
    1. Advertisements

  3. Adna rim

    Adna rim Guest

    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
     
    Adna rim, Mar 2, 2008
    #3
  4. Alle Sunday 02 March 2008, Adna rim ha scritto:
    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
     
    Stefano Crocco, Mar 2, 2008
    #4
  5. Adna rim

    Adna rim Guest

    Many thanks now it works perfectly :)

    greets
     
    Adna rim, Mar 2, 2008
    #5
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.