Are you sure the image on disk has changed?
Any reason you do not just transfer the image within the application?
Cheers,
_
Are you sure the image on disk has changed?
Any reason you do not just transfer the image within the application?
Cheers,
_
yes,the image on disk has changed.
In fact,I also have a button to check the same code.On button click the code works:
Qt Code:
void Dialog_user::on_btn_Stop_clicked() { }To copy to clipboard, switch view to plain text mode
I am not transferring the image within application because I am unable to refresh the image.It takes the same image as it took during the build time,even though the image on disk changes.
Is your image processing thread closing the file (or at least flushing it) so the contents are physically written to the disk? If the thread simply keeps the file open while continuously updating it, the changes might simply be in the disk cache and not actually in the file itself.I am successfully getting "inside slot" message,which indicates that ImageRefreshSlot() has been called,but still the image is not getting refresh
Also, if your app doesn't return to the event loop after the "image finished" signal is handled, the UI won't update. Handling the button click *does* return the app to the event loop, so the pixmap *will* be updated.
And who is this "atathamquin" who keeps thanking every post, no matter what it says? Seems to be a few of these types running around the forum lately.
@anda_skoa: I have checked the file physically and also its timestamp also.It is indeed changing everytime.
Also I am not passing image as a parameter through my signal because I need to read the file again and again and hence I am doing it on a physical file and i know its location,so no need to pass.
@d_stranz: yes,the image processing thread is closing the file and the contents are physically written to the disk.
I think you are correct,that it is not returning to the event loop after "image finished" signal is handled..hence the UI is not updating.
Pl tell how to return to the event loop,as I am unable to do so..
You are using a relative path to the file. It seems quite possible you are writing to one file called abc.bmp and reading from another.
There is only 1 file abc.bmp.
I have verified it as I am initializing the label with it and also using external button_click event to run the same code and it is working correctly.
I am afraid I can't follow. It really doesn't matter how the file is being accessed, does it?
Your worker thread manipulates a QImage, right? It saves the data to file after it is done, right? Why not just also emit the image via signal for displaying?
That avoids any race condition on file access, avoids unnecessary disk I/O, avoid unnecessary image decoding.
Cheers,
_
My worker thread manipulates a bitmap image(stored on file) and I am using QPixmap to display it inside a label.
I emit the signal just after the thread finishes manipulating that bitmap image.
Hence i need to read the file everytime and for that I am using a slot mechanism to reset the image in the label everytime a signal is emmited.
Here is the code inside the slot:
Qt Code:
To copy to clipboard, switch view to plain text mode
Yes but why do you need disk access ? Worker can process the image and send the processed result directly to the display thread, what's wrong with that
now you have this:
why not have this:Qt Code:
[load image from disk] --> process it --> [save to disk] --> inform gui that image is updated --> [load from disk] --> displayTo copy to clipboard, switch view to plain text mode
Qt Code:
[load image from disk] --> process it --> inform gui that image is updated, send the image via signal --> displayTo copy to clipboard, switch view to plain text mode
prkhr4u (9th December 2013)
Can you pl tell how to pass image via signal,I am unable to do so.
You add QImage as a parameter of the signal
And you pass the image at emitQt Code:
{ Q_OBJECT signals: };To copy to clipboard, switch view to plain text mode
Qt Code:
emit ImageRefreshSignal(image); // or image.copy() if the thread continues to use "image"To copy to clipboard, switch view to plain text mode
Similar signature changes to slot and connect obviously
Cheers,
_
prkhr4u (9th December 2013)
I have done the changes and now am sending the image via signal,but still I am unable to refresh the image.
Here is what I have done:
Signal emmited like:Qt Code:
{ Q_OBJECT private: void run(); public: signals: };To copy to clipboard, switch view to plain text mode
slot method called like:Qt Code:
QImage img; img.load("abc.bmp"); emit ImageRefreshSignal(img);To copy to clipboard, switch view to plain text mode
//dialog_user.hQt Code:
{ qDebug()<<"inside slot"; }To copy to clipboard, switch view to plain text mode
the connection is as follows:Qt Code:
{ Q_OBJECT public: ~Dialog_user(); private slots:To copy to clipboard, switch view to plain text mode
I have checked the mechanism, and the message "inside slot" is being printed,but the image is not getting refreshed.Qt Code:
To copy to clipboard, switch view to plain text mode
Why do you load the image before sending it ? Can't you send the processed object ? Can we see the image processing code ?
Bookmarks