Project

General

Profile

Actions

Improvements #13393

open

WText with WResource

Added by Igor Ulyanov 2 months ago. Updated about 1 month ago.

Status:
Feedback
Priority:
Normal
Assignee:
Target version:
-
Start date:
01/07/2025
Due date:
% Done:

0%

Estimated time:

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.

Actions #1

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.

Actions #2

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 from WResource and established a WLink to it.
  • Next, I created a hidden WWidget containing a WImage 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 the setText method of the WText 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.

  1. 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.
Actions

Also available in: Atom PDF