How to refresh a WImage based on an event
Added by Jim Fred about 11 years ago
I'm having troubles refreshing a WImage. The source of the image is an external device - a webcam - and this much works: I create the WImage using something like myWImage = new WImage( "http://myWebCamImgUrl" )
which results in html code with <img id="xxxxxxxxx" alt="" src="http://myWebCamImgUrl">
. The image displays as expected and it will refresh with a browser refresh.
To refresh repeatedly, this works: I tried myWImage->imageLoaded().connect("function(o) { o.src='http://myWebCamImgUrl'; }");
as suggested at [[[http://redmine.webtoolkit.eu/boards/1/topics/6976]]].
But, I want to avoid a continuous refresh of the image so I attempted to refresh this image with, for testing purposes, a button click. In the button-click-handler, I tried myWImage->setImageLink()
as recommended at [[[http://redmine.webtoolkit.eu/boards/2/topics/6281?r=6282#message-6282]]]. I also tried various combinations of refresh()
, load()
, hide
and show()
and the result is that the image doesn't refresh - it continues to show the original image when the page was first rendered. I can change the alt text in my button-click-handler and I can see the changed alt text in the browser but the image remains unchanged. I can also see WText widgets change in the button-click-handler.
Any suggestions to refresh a WImage?
Replies (2)
RE: How to refresh a WImage based on an event - Added by Jim Fred about 11 years ago
I found a way to update the image: I can use myWImage->setImageLink( url )
without a refresh()
if I change url by alternately adding or removing a trailing space on each call. So I have roughly the equivalent of an sprintf that looks at a static bool to determine if a trailing space should be appended or not. The static bool flips on each call. If there's a more elegant way to do this, please let me know.
RE: How to refresh a WImage based on an event - Added by Koen Deforche about 11 years ago
Hey,
I've updated the documentation to state that refresh() almost never does what one hopes (it is one of those methods that got a name that gives lots of people the hope that it will solve whatever problem they are currently having. Imagine a refresh() function could exist for vegetables, or meat, or myself, I can imagine I would use it too!).
As to why the image does not update: a browser will not re-fetch the same image twice. It will not even check whether the data itself actually changed (unless you really push him), because things get cached.
The only trick that reliably works: add a '?version=...' field which you increment. This 'query string' is ignored for static contents but it prompts the browser to get the new data.
Regards,
koen