Results 1 to 2 of 2

Thread: Problem with tableview "randomly" scrolling to top

  1. #1
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem with tableview "randomly" scrolling to top

    Hey!

    I've been developing a program with two custom listviews (custom views derived from QTableView) in it. They both read from the same model which is a derived QSortFilterProxyModel that in turn has a QSqlQueryModel as sourcemodel.

    I've recently discovered that "sometimes" when the QSqlQueryModel is updated the listview "pops" all the way to the top.
    The QSqlQueryModel is updated every 2 seconds in a separate thread against a local MySQL server.
    How many updates it takes before the list "pops" varies from maybe 5 to 10 minutes. An interesting note is that if I'm running a virus scan the pop is much more prone to occur and the list seldom go a minute without popping to the top.
    It doesn't seem to matter whether I use it intensely (clicking and scrolling around like a mad man) or just sit back in my chair and watch.

    I realize it's impossible to tell what the error is providing there is many custom classes and loads of code. But I'm just wondering if this type of behavior is ringing a bell for anyone?
    Any ideas on where to start looking?

    Thank you!
    /Tottish

  2. #2
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with tableview "randomly" scrolling to top

    I'm thinking that this behavior might be caused by the tableviews trying to read from the source model (via the proxy-model) while the update-thread is writing to it. Does this make sense?
    If so, can I block the QSqlQueryModel instance from being read while it is being updated from a different thread?
    From what I've come to learn from the docs on QMutex and QReadWriteLock they are used to protect functions/methods rather than instances of objects, however I don't have a clear understanding of these.

    Thanks
    /Tottish

    EDIT: Well, it seems that indeed was the problem. Though I couldn't manage to lock the model object I instead created a buffer model object so that the listviews can never attempt to read from the model while the update is being performed.
    That did the trick but it seems like a rather boring solution.
    Is there anything wrong with doing this? Would some kind of lock be preferable?
    The model should never be more than about 300 rows and 30 columns so I'm guessing it shouldn't be too hard on the performance?

    EDIT2: To further clarify: As it is set up right now, the QSqlQueryModels are private members of the updatethread class and sends pointers (to the listviews) to these via a signal that is emitted upon update complete.

    Thanks
    /Tottish
    Last edited by Tottish; 16th February 2011 at 19:43.

Similar Threads

  1. Replies: 1
    Last Post: 7th April 2010, 21:46
  2. "Smooth" Scrolling, QGraphicsView
    By nearlyNERD in forum Qt Programming
    Replies: 5
    Last Post: 25th February 2010, 17:18
  3. Replies: 3
    Last Post: 8th July 2008, 19:37
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 15:58

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.