Results 1 to 15 of 15

Thread: QGraphicsView not being updated

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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: QGraphicsView not being updated

    Please provide more than one or two lines of code. It is important to see the context of a particular call. If you use some variable in a code snippet, please explain what it is, we're not trueseers.
    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. #2
    Join Date
    Jan 2010
    Posts
    190
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    18
    Thanked 1 Time in 1 Post

    Default Re: QGraphicsView not being updated

    Sure, the methods I already posted are more or less like those are in my code. The only difference is that imageReady and the slot imageGenerated accept two parameters instead of one. I didn't report the implementation of imageGenerated which is this:

    Qt Code:
    1. void Class2::imageGenerated(QImage image, QString string) {
    2. Class* item = itemsMap.value(string);
    3. item->setImageLoaded(image);
    4. }
    To copy to clipboard, switch view to plain text mode 

    where Class2 is a subclass of QGraphicsScene and itemsMap is a QMap which maps strings to objects of class Class. Sorry I made a mistake in the other post, in fact IconViewItem was Class.
    This method I reported calls the method setImageLoaded of class Class that I reported above (it was complete, it only lacked another assignation of image, no more lines).

    Of course the connect statement was:

    Qt Code:
    1. connect(loader, SIGNAL(imageReady(QImage, QString)), this, SLOT(imageGenerated(QImage, QString)));
    To copy to clipboard, switch view to plain text mode 

    The code I reported for the worker thread was complete, I only removed some lines where I set the size I want for imageReader before loading (I report in case it's relevant):

    Qt Code:
    1. QImageReader imageReader(dir->absoluteFilePath(filesList->at(i)));
    2. if (imageReader.size().height() >= imageReader.size().width())
    3. imageReader.setScaledSize(QSize(imageReader.size().width()*64/imageReader.size().height(), 64));
    4. else imageReader.setScaledSize(QSize(64, imageReader.size().height()*64/imageReader.size().width()));
    To copy to clipboard, switch view to plain text mode 

    where dir and filesList are local pointers to QDir and QStringList respectively.

  3. #3
    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: QGraphicsView not being updated

    So "loader" is an instance of a subclass of QThread?

    What does the program do while the thread is working? Are you able to resize windows of the application, scroll the view, etc.?
    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.


  4. #4
    Join Date
    Jan 2010
    Posts
    190
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    18
    Thanked 1 Time in 1 Post

    Default Re: QGraphicsView not being updated

    Sorry, forgot to specify loader. loader is a subclass of QThread whose run() method I already reported.
    The program works correctly except immediately after it is loaded. Subsequent loaders work correctly. I create it this way:

    loader = new ThumbnailLoader(dir, filesList);

    where dir and filesList are those I reported.
    And I start it in a method this way:

    Qt Code:
    1. delete loader->dir;
    2. delete loader->filesList;
    3. loader->dir = dir;
    4. loader->filesList = imagesList;
    5. loader->start(QThread::LowestPriority);
    To copy to clipboard, switch view to plain text mode 

    The reason why I delete and then reassign is that this method is called many times when the user requests (parameters in the constructor were absolutely unuseful). It works correctly every time except the first which is right after the program loads. After the first call, while the loader works, I can do whatever I want, like scrolling the QGraphicsView, stopping it, etc... The first time instead, it works, but the QGraphicsView is simply not showing anything until I click anywhere on the application. After I click, the images already processed are suddenly rendered and the QGraphicsView starts to show them as soon as they are loaded (which is the expected behavior, and the behavior the program has in some systems, always Windows CE). I hope I've been able to make the behavior clear.

    EDIT: I forgot to mention that the above portion of code is placed in a method which is called, the first time (which is the only case in which sometimes it fails to update correctly), in the constructor of a subclass of a QGraphicsScene (the same which has to render the images).

  5. #5
    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: QGraphicsView not being updated

    Please provide a minimal compilable example reproducing the problem.
    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.


  6. #6
    Join Date
    Jan 2010
    Posts
    190
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    18
    Thanked 1 Time in 1 Post

    Default Re: QGraphicsView not being updated

    This is a compilable example showing the issue I'm talking about. It doesn't happen always, but quite often. Tried this on Windows Vista and Windows CE.

    Under Windows Vista seems to work always correctly. Under Windows CE, sometimes it shows the images as soon as they are loaded, sometimes it is necessary to click in some place before the application shows the images.

    In this example I didn't add an update explicitly, in my previous application there was an explicit call to the update method, but it seems this is not needed, at least not under Windows Vista.

    If you need to change the path where the images are located and the filter to test it, change whatever you need in workerthread.cpp.

    Thanks for any advice!
    Attached Files Attached Files

  7. #7
    Join Date
    Jan 2010
    Posts
    190
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    18
    Thanked 1 Time in 1 Post

    Default Re: QGraphicsView not being updated

    Isn't anyone able to reproduce this issue?

  8. #8
    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: QGraphicsView not being updated

    You can't manipulate QPixmaps in worker threads, neither can they be transfered across threads (use QImage instead). Also remember the WorkerThread object doesn't live in the thread it represents. See if it all helps.
    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.


  9. #9
    Join Date
    Jan 2010
    Posts
    190
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    18
    Thanked 1 Time in 1 Post

    Default Re: QGraphicsView not being updated

    You're absolutely right. My bad. I will correct this mistake. I used QPixmaps instead of using QImages. But I did this only in the example. In my code I originally used QImages. Are you able to reproduce this situation anyway?
    Thanks for your answers!

  10. #10
    Join Date
    Jan 2010
    Posts
    190
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    18
    Thanked 1 Time in 1 Post

    Default Re: QGraphicsView not being updated

    I made some more investigation on this, and found out that the method in my GUI thread that should have painted the images on the view was not executed until the user clicked. I therefore changed the type of connection to Qt:irectConnection. Unfortunately, now the method is called immediately, but still the QGraphicsView is not updated anyway until the user clicks.
    Any other idea?
    Thanks!

Similar Threads

  1. Layout not updated when sizeHint changes
    By ArmanS in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2010, 14:31
  2. QTextEdit not being updated
    By doggrant in forum Qt Programming
    Replies: 3
    Last Post: 2nd September 2009, 17:25
  3. elements not updated
    By danesh in forum Qt Programming
    Replies: 2
    Last Post: 2nd April 2009, 08:35
  4. HaiQ updated for Qt 4.4
    By magland in forum Qt-based Software
    Replies: 8
    Last Post: 19th September 2008, 11:42
  5. QHash only getting updated not populated
    By quickNitin in forum Newbie
    Replies: 2
    Last Post: 13th July 2006, 11:32

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.