Results 1 to 2 of 2

Thread: How to prevent opening the same record in a new window more than once in QTableView ?

  1. #1
    Join Date
    Sep 2016
    Location
    U.K.
    Posts
    16
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default How to prevent opening the same record in a new window more than once in QTableView ?

    Hi All,
    I wonder if anyone can help, I have a QTableView where I'm displaying list of records, to display further details of any record I'm opening a new window by clicking on the record, all well apart from that I can open the SAME record more than once, How can I prevent this happening ?

    this is what I have so far
    Qt Code:
    1. while(qry.next())
    2. {
    3. model->setQuery(qry);
    4. }
    5. connect(ui->tableView_visitLog, SIGNAL(pressed(const QModelIndex&)), this,
    6. SLOT(on_tableView_visitorLog_clicked(const QModelIndex&)));
    7.  
    8.  
    9. void ControlPanel::on_tableView_visitorLog_clicked(const QModelIndex& index)
    10. {
    11. const QAbstractItemModel* tableModel = ui->tableView_visitLog->model();
    12. int visitor_id = tableModel->data(tableModel->index(index.row(),0), Qt::DisplayRole).toInt();
    13. visitordetails = new VisitorDetails(visitor_id, this);
    14. visitordetails->show();
    15. }
    To copy to clipboard, switch view to plain text mode 

  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: How to prevent opening the same record in a new window more than once in QTableVi

    Add a QHash member to your class that uses the visitor_id value as the key and has a pointer to the VisitorDetails as the value.

    When you get into that slot you first check if you have an entry already and only create one if you don't.
    If you have one you can still call show() and raise() on it to make it come to the front (if there are more than one of these open)

    Cheers,
    _

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

    zed220 (30th September 2016)

Similar Threads

  1. Qtablewidget insert Record from Qtableview
    By advseo32 in forum Qt Programming
    Replies: 1
    Last Post: 22nd August 2013, 11:26
  2. opening a QTableView window with a pushbutton
    By willief in forum Qt Programming
    Replies: 4
    Last Post: 7th April 2011, 20:57
  3. Replies: 3
    Last Post: 26th March 2010, 05:32
  4. Replies: 0
    Last Post: 11th March 2010, 08:41
  5. QTableView, add new record?
    By grellsworth in forum Qt Programming
    Replies: 6
    Last Post: 5th July 2007, 16:08

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.