Results 1 to 4 of 4

Thread: Connecting tableWidget signal and external slot

  1. #1
    Join Date
    Oct 2010
    Posts
    12
    Thanks
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Connecting tableWidget signal and external slot

    Hi there!
    I want to connect cellDoubleClicked() from tableWidget to custom slot.
    In my main.cpp i have instance of QMainWindow class - window.
    I tried
    Qt Code:
    1. QObject::connect( window, SIGNAL(cellClicked(int, int)),window, SLOT(onCellClicked(int, int)));
    To copy to clipboard, switch view to plain text mode 
    but it doesn't work. onCellClicked(int, int) is my custom slot. Any suggestions?
    Last edited by qutron; 17th November 2010 at 13:55.

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Connecting tableWidget signal and external slot

    You must use the cellDoubleClick(int, int) signal of your tableWidget object.

    So, if your tableview member is public, the connect should look something like:
    QObject::connect( window->Your_tableWidget_name, SIGNAL(cellDoubleClicked(int, int)),
    window, SLOT(onCellClicked(int, int))
    );

    But most likely the tableWidget is private (or the ui object or pointer is private, depends on your project), then you can create another signal in your mainwindow class, connect the cellDoubleClicked(int, int) signal with the signal you create (you can connect two signals) and use this signal to finally connect to the slot that you need to execute.

  3. The following user says thank you to Zlatomir for this useful post:

    qutron (17th November 2010)

  4. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Connecting tableWidget signal and external slot

    the first argument has to be a pointer to your table widget.

    EDIT: too late.

  5. #4
    Join Date
    Oct 2010
    Posts
    12
    Thanks
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Connecting tableWidget signal and external slot

    But most likely the tableWidget is private (or the ui object or pointer is private, depends on your project), then you can create another signal in your mainwindow class, connect the cellDoubleClicked(int, int) signal with the signal you create (you can connect two signals) and use this signal to finally connect to the slot that you need to execute.
    Just tried to do that. It works))

    Thanks.

Similar Threads

  1. Replies: 8
    Last Post: 13th July 2010, 14:08
  2. Replies: 2
    Last Post: 9th September 2009, 00:26
  3. Connecting signal to custom slot?
    By dbrmik in forum Qt Tools
    Replies: 2
    Last Post: 30th April 2009, 09:28
  4. Connecting two classes with slgnal and slot
    By Benjamin in forum Newbie
    Replies: 2
    Last Post: 22nd January 2009, 13:16
  5. Connecting to a slot not within an Obejct
    By Matze-o in forum Qt Programming
    Replies: 2
    Last Post: 10th November 2008, 14:02

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.