Bug #6724
closedTypo in documentation for Wt::WMessageResourceBundle
0%
Description
It is given as
Wt::WText *welcome = new Wt::WText(tr("welcome-visitor").arg("Bart"));
instead of
Wt::WText *welcome = new Wt::WText(tr("welcome-text").arg("Bart"));
In order to add this widget to a container, the widget should be created with std::make_unique<>() or Wt::cpp14::make_unique<>() function.
Updated by Roel Standaert over 6 years ago
- Status changed from New to Resolved
I changed welcome-visitor
to welcome-text
in the source.
I'm not sure what you want to say with:
In order to add this widget to a container, the widget should be created with std::make_unique<>() or Wt::cpp14::make_unique<>() function.
Updated by Ansal P.A. over 6 years ago
I mean if i create welcome as a pointer like this
Wt::WText *welcome = new Wt::WText(tr("welcome-text").arg("Bart"));
I need to typecast it in order to add to another widget.
I cannot add this 'welcome' widget directly to root(). right?
root()->addWidget(welcome);
I need to typecast it. right?
root()->addWidget((std::unique_ptrWt::WText)welcome);
I don't know much about it. Correct me if i am wrong.
Updated by Roel Standaert over 6 years ago
You don't cast the pointer to a unique_ptr, you create a unique_ptr out of it. I don't recommend you do that, though. It's best practice to create it with std::make_unique
if you have a compiler that supports C++14 (or you can use Wt::cpp14::make_unique
).
So like that:
std::unique_ptr<Wt::WText> welcome = std::make_unique<Wt::WText>(tr("welcome-text").arg("Bart"));
root->addWidget(std::move(welcome));
// welcome == nullptr now, so don't use it
Is that clear?
This could be a bit more useful, and a bit shorter:
Wt::WText *welcome = root->addNew<Wt::WText>(tr("welcome-text").arg("Bart"));
// you can now still use welcome
Updated by Ansal P.A. over 6 years ago
Roel Standaert wrote:
You don't cast the pointer to a unique_ptr, you create a unique_ptr out of it. I don't recommend you do that, though. It's best practice to create it with
std::make_unique
if you have a compiler that supports C++14 (or you can useWt::cpp14::make_unique
).So like that:
[...]
Is that clear?
This could be a bit more useful, and a bit shorter:
[...]
The last sentence anwers my question. I am already using std::make_unique<>() for everything. But in the example you are creating just a pointer. That is why all these confusions. Anyway the last sentence answer my question, including how to add a widget to another and still use the child widget pointer. When using std::move() we loose the child pointer. Which sometimes gives me trouble. Thanks for explaining anyway. I appreciate your response.
Updated by Roel Standaert about 6 years ago
- Status changed from Resolved to Closed