Results 1 to 3 of 3

Thread: how to emit signal in the model in this application?

  1. #1
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question how to emit signal in the model in this application?

    Hi,
    I use boost::circular_buffer as underly data stru in my own model,
    I set capacity of circular_buffer in advance. For example , 30000. If I push_back more than 30000 data. the first ones will be deleted.
    The question is: What signal should I emit to notice the QTableView to act correctly?

    I tyr emit layoutabouttobechanged() layoutChanged(), but the selection stateis not act properly with the data push_back!

    Another test is
    Qt Code:
    1. beginRemoveRows(QModelIndex(),0,alarms.size()-1);
    2. endRemoveRows();
    3. beginInsertRows(QModelIndex(),max_alarm_num-alarms.size(),max_alarm_num-1);
    4. endInsertRows();
    To copy to clipboard, switch view to plain text mode 
    It seems work, but I doubt it as in the Qt Assistant
    When reimplementing insertRows() in a subclass, you must call this function before inserting data into the model's underlying data store.
    Jerry

  2. #2
    Join Date
    Feb 2009
    Posts
    24
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to emit signal in the model in this application?

    The answer to your question depends on what you want to happen in the view. If you just want the new value to appear in the same place as the old value that was overwritten in the circular_buffer, all you need to do is call dataChanged() for the item that was changed.

    If you want it to appear somewhere else in the view(say, the old value was at the top of the table view, and you want the new value to appear at the end of that view) things get a bit more complicated. In this case, you would need to call both beginRemoveRows()/endRemoveRows() and beginInsertRows()/endInsertRows(). The first pair would let the view know that the old value doesn't exist anymore, thus removing it from the top of the table, and the second pair inserts the new data at the end of the view.

  3. #3
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to emit signal in the model in this application?

    Quote Originally Posted by abernat View Post
    The answer to your question depends on what you want to happen in the view. If you just want the new value to appear in the same place as the old value that was overwritten in the circular_buffer, all you need to do is call dataChanged() for the item that was changed.
    In fact, after you push_back datas into the circular_buffer which is full, in the tableview's view, all the data has changed. So I think this way is not proper. And I test it in my program, it doesn't work.


    If you want it to appear somewhere else in the view(say, the old value was at the top of the table view, and you want the new value to appear at the end of that view) things get a bit more complicated. In this case, you would need to call both beginRemoveRows()/endRemoveRows() and beginInsertRows()/endInsertRows(). The first pair would let the view know that the old value doesn't exist anymore, thus removing it from the top of the table, and the second pair inserts the new data at the end of the view.
    I called the two pairs after I changed the circular_buffer's data. But Qt Assistant says call beginRemoveRows() / beginInsertRows() before you changed the data, call endRemoveRows() / endInsertRows() after you changed the data. I cann't do this for according to the size of circular_buffer, I emit different signals.

    I use QSortFilterProxyModel to sort and filt the data in the model. My program should work as efficient as it can in the extreme situation which insert about 1000 datas(my own data type) per second.But there is efficient problem when the circular_buffer is full. The cpu load is twice about it when the circular_buffer is not full when I only emit beginInsertRows()/endInsertRows() ! How can I improve it ?
    Jerry

Similar Threads

  1. how to emit signal in a static function ?
    By cxl2253 in forum Qt Programming
    Replies: 32
    Last Post: 7th July 2016, 22:36
  2. emit qt signal is very slow how it can be optimized?
    By sawerset in forum Qt Programming
    Replies: 8
    Last Post: 30th December 2008, 10:21
  3. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 08:16
  4. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 08:04
  5. how to know which button emit the signal?
    By coder1985 in forum Qt Programming
    Replies: 2
    Last Post: 12th January 2008, 15:26

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.