WTable and the Widgets inside

Added by Sebastian Fett 3 months ago

Hey,
I recently had to swap from JS and Python to WT so im pretty new to WT in general.
The tutorials show how to create a table and fill it with information. Currently I am adding rows based on button click and want to read all those entries at once.
Ive tried it as I was used to in JS but I am not getting anywhere close to my expectations. Returning the table->elementAt(row,column) gives me a WTableCell of which i can get the widget with the ID (since it has only 1 entry per cell that should work fine.
But now im stuck trying to get say the content of my WLineEdit at said TableCell

Wt::WLineEdit *line1 = new Wt::WLineEdit(Wt::WString::fromUTF8(" "));
table->elementAt(rows, 1)->addWidget(line1);

Sets the new row and LineEdit, then I try to receive it wiith

Wt::WString = table->elementAt(x,y)-> <way to the content of the cell> ->text();
I've tried it with getting the children from the TableCell but that didnt work either.
I must admit I miss the ability to work with JS objects in the browser console.
Thanks in advance


Replies (4)

RE: WTable and the Widgets inside - Added by lm at 3 months ago

Sebastian Fett wrote:

Wt::WString = table->elementAt(x,y)-> <way to the content of the cell> ->text();

I've tried it with getting the children from the TableCell but that didnt work either.

You're using WT version 3? What error do you get?

RE: WTable and the Widgets inside - Added by Sebastian Fett 3 months ago

Yes I am using WT v 3, my issue is I cannot figure out how to get the widget at the Table Cell. Children gives me a WWidget which cannot call the text.
So in the case with children the error would be that WWidget has no member named "text()". Do I need to cast the result of children to WLineEdit?
I feel like I am missing something cuz in JS I could just get the element at the table cell and one of the children would be the WLineEdit, should be close to that in WT I guess?
Id be super happy if you could supply me with an example which reads from a table entry so I could figure out how to call the entries
Thanks

RE: WTable and the Widgets inside - Added by Wim Dumon 3 months ago

Sebastian,

WTableCell inherits from WContainerWidget, a widget which contains other widgets. If you only added one widget, your WLineEdit will be at widget(0) (or children()[0]). This returns indeed a WWidget, which will be of type WLineEdit (WLineEdit inherits from WWidget). Use C++'s dynamic_cast<WLineEdit *>(...) to cast the WWidget to the WLineEdit, and you'll be able to access the text() method.

Wim.

RE: WTable and the Widgets inside - Added by Sebastian Fett 3 months ago

Thank you, haven't worked a lot with c++ so far so I completely missed the dynamic cast part.
Works perfectly fine now.

(1-4/4)