Improvements #13393
openWText with WResource
0%
Description
Is there a way to load WText widget dynamically with WLink and WResource like it is done in WImage? It is needed for slowly generated text at server side.
Updated by Matthias Van Ceulebroeck about 1 month ago
- Status changed from New to Feedback
- Assignee set to Igor Ulyanov
Hello Igor,
apologies for the delay.
There is no way to directly use WText
as you can do with WImage
for example. Depending on how you handle this data:
- I suspect that
WMemoryResource
may be what you are looking for. - you can maybe take a look at
WStreamResource
, if spooling it to a file is fine. But that may not be sufficient for your use-case
If this doesn't quite cover it, and you are looking more of a tail -f {file}
-like approach, you want to have a WContainerWidget
(or WTemplate
) to which WText
items are appended. To ensure that the server is able to push data to the client, take a look at WApplication::enableUpdates().
I hope that helps you along, and if not, please let me know.
Updated by Igor Ulyanov about 1 month ago
I have found a workaround for this issue after some time:
- Initially, I created a custom
TextResource
class that inherits fromWResource
and established a WLink to it. - Next, I created a hidden
WWidget
containing aWImage
that references the link. The purpose of this link is to initiate the download of text content instead of an image. - I then connected a custom signal from the
TextResource
to thesetText
method of theWText
widget that needs to display the text.
This method works because Wt attempts to load all images, regardless of whether they are displayable or not.
- To address issues with updating widgets using this workaround, I found it necessary to perform an additional step: WServer::instance()->post(sessionId(), this { std::this_thread::sleep_for(std::chrono::milliseconds(10)); triggerUpdate(); }); in main application thread to update all widgets by this custom signals.