Results 1 to 7 of 7

Thread: Keeping your application responsive

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Keeping your application responsive

    Quote Originally Posted by javimoya View Post
    wysota... do you know an EASY book or website to start learning about threads and pararell programming (basic concepts)? it's focused on Qt it would be nice.
    Well... Silbershatz's book on operating systems is a classic. Besides that I don't know any such resources. In my opinion my Qt Quarterly article filled some of the gaps regarding Qt perfectly when it comes to practical approach to SIMD. If you need something specific then say so, I can try to do some research and write more about it. But basically it takes a lot of thinking and practice to understand threading and parallel programming on a decent level. You can look for articles on "grid computing" (or cloud computing), that's a popular subject nowadays and there are a lot of conferences dedicated to it, like this one: http://www.ppam.pl/ to just name the one I participated in (and it helped start my interest in parallel programming). The basic thing you should undestand is how processes in your OS work, then you can learn about threads and synchronization and then you can focus on more high-level aspects like parallel programming, SIMD and stuff like that. OpenCL or equivalent should then follow if you want a many-core (note, not "multi-core") solutions.

    Oh, and good computer science studies also help a lot

    Quote Originally Posted by chezifresh View Post
    Good link. Aside from some details, that describes basically what my thumbnailing service does.
    The main difference is that the solution described in the article adjusts to your machine and is more high-level.

    The problem I ran into was that my thumbnailing service sometimes produces thumbnails so fast that the UI thread is swamped with repaint events, and causes the UI to become unresponsive.
    There is an easy solution - process the data you receive in batches. The simplest way is to use a timer, like so:
    Qt Code:
    1. void MyModel::newImageReady(const QImage &img) {
    2. if(!m_batchTimer.isActive()) m_batchTimer.start(1000); // timer is single shot
    3. m_pending << img;
    4. if(m_pending.size()>=10) {
    5. // force update when 10 images are waiting
    6. m_batchTimer.stop();
    7. batchTimerTimeout();
    8. }
    9. }
    10.  
    11. void MyModel::batchTimerTimeout() {
    12. int minRow = rowCount(), maxRow = -1;
    13. foreach(const QImage &img, m_pending) {
    14. QModelIndex idx = indexFromText(img.text("index"));
    15. minRow = qMin(minRow, idx.row());
    16. maxRow = qMax(maxRow, idx.row());
    17. QPixmap px = QPixmap::fromImage(img);
    18. m_data[idx.row()].pixmap = px;
    19. }
    20. m_pending.clear();
    21. emit dataChanged(index(minRow, 0), index(maxRow, columnCount()-1));
    22. }
    To copy to clipboard, switch view to plain text mode 

    The way I approached this was to have my thumbnail scaling/loading threads emit a signal with the QImage it generated. The thumbnail service adds that thumbnail to a queue of thumbnails that need to be dispatched. Then it waits for a timer to go off. The timeout() signal is connected to a slot that dispatches the thumbnails:
    I should really read posts to the end before answering them Yeah, good approach but mine is better - queue in the model, not in the service, worker threads can't create pixmaps.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. The following user says thank you to wysota for this useful post:

    javimoya (30th March 2011)

Similar Threads

  1. keeping aspect ratio while resizing
    By franco.amato in forum Qt Programming
    Replies: 2
    Last Post: 19th November 2009, 21:12
  2. Replies: 6
    Last Post: 20th July 2009, 06:48
  3. keeping a widget to be square
    By jmsbc in forum Qt Programming
    Replies: 5
    Last Post: 16th June 2009, 20:47
  4. How to keep the GUI responsive?
    By drjones in forum Qt Programming
    Replies: 8
    Last Post: 16th July 2008, 15:33
  5. Keeping focus at bottom of QListView
    By jakamph in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2006, 15:45

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.