Results 1 to 8 of 8

Thread: selectionChanged() signal in qtableview

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: selectionChanged() signal in qtableview

    No problem, we've all been there... That is just one reason why I prefer the new connect syntax that avoids the use of SIGNAL/SLOT macros. The equivalent for your case would be:

    Qt Code:
    1. connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &WhateverYourClassIsNamed::on_tableViewSelection);
    To copy to clipboard, switch view to plain text mode 

    Let the compiler do the work for you and catch parameter mismatches, etc.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: selectionChanged() signal in qtableview

    Quote Originally Posted by jthomps View Post
    No problem, we've all been there... That is just one reason why I prefer the new connect syntax that avoids the use of SIGNAL/SLOT macros.
    Indeed, but that became available in Qt5, according to breakthecode's profile they are using Qt4.

    It is possible to make the connect a bit less verbose though, i.e. removing the const references

    Qt Code:
    1. connect(ui->tableView->selectionModel(),
    2. SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
    3. this,
    4. SLOT(on_tableViewSelection(QItemSelection, QItemSelection)));
    To copy to clipboard, switch view to plain text mode 
    Also, if your slot doesn't need the arguments, you can use a slot with fewer arguments than the signal has., e.g.
    Qt Code:
    1. connect(ui->tableView->selectionModel(),
    2. SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
    3. this,
    4. SLOT(on_tableViewSelection()));
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. Detect when the content of a cell of QTableView is changed
    By qt_developer in forum Qt Programming
    Replies: 5
    Last Post: 21st August 2021, 16:00
  2. Replies: 1
    Last Post: 29th May 2014, 05:16
  3. Value changed in a QTableView field
    By nittalope in forum Newbie
    Replies: 4
    Last Post: 12th August 2009, 09:21
  4. problem with changed() signal emitted by QGraphicsScene
    By sanjayshelke in forum Qt Programming
    Replies: 1
    Last Post: 29th April 2009, 13:55
  5. Replies: 9
    Last Post: 23rd November 2006, 11:39

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
  •  
Qt is a trademark of The Qt Company.