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.
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.
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:
Class* item = itemsMap.value(string); item->setImageLoaded(image); }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:
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:
if (imageReader.size().height() >= imageReader.size().width()) 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.
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.?
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:
delete loader->dir; delete loader->filesList; loader->dir = dir; loader->filesList = imagesList;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).
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!
Isn't anyone able to reproduce this issue?
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.
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!
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!
Bookmarks