Project

General

Profile

WStandardItem User Data

Added by Aziz Gokhan Narin about 3 years ago

Hello,

*class MyClass myClass;

Wt::WStandardItem item("Trial");

item->setData(Wt::cpp17::any(myClass), Wt::ItemDataRole::User);*

I put the my own data into user data part. there is no matter so far. However when I try to my info like

MyClass myClass = Wt::cpp17::any_cast(model->item(row, 0)->data(Wt::ItemDataRole::User));

I got the error like that;

error: cannot bind rvalue reference of type 'MyClass&&' to lvalue of type 'std::remove_reference::type' {aka 'MyClass'}
return *p;
^
/usr/local/include/Wt/cpp17/any/any.hpp

I tried to get && but yet dows not work. I need your assistance to solve the problem.

Thanks in advance.

Gokhan


Replies (2)

RE: WStandardItem User Data - Added by Aziz Gokhan Narin about 3 years ago

I solved the problem.

First, the object should be moved into user data part. Because "any" type can not deep copy.

`template
MyTemplateClass
{
std::string id;
T *var;
};

MyClass
{
std::vector list;
};

MyTemplateClass myTemplate;

myTemplate.id = "myId";
myTemplate.var = new MyClass();

myTemplate.var->list = std::vector(5);

Wt::WStandardItem item("Trial");

item->setData(Wt::cpp17::any(std::move(myTemplate)), Wt::ItemDataRole::User);

...

MyClass *myClass = Wt::cpp17::any_cast>(item->data(Wt::ItemDataRole::User))->var;`

I've just concerned what if occurs memory leak, but I could not see like that. I think because of namespace of that.

RE: WStandardItem User Data - Added by Aziz Gokhan Narin about 3 years ago

Aziz Gokhan Narin wrote:

Hello,

*class MyClass myClass;

Wt::WStandardItem item("Trial");

item->setData(Wt::cpp17::any(myClass), Wt::ItemDataRole::User);*

I put the my own data into user data part. there is no matter so far. However when I try to my info like

MyClass myClass = Wt::cpp17::any_cast(model->item(row, 0)->data(Wt::ItemDataRole::User));

I got the error like that;

error: cannot bind rvalue reference of type 'MyClass&&' to lvalue of type 'std::remove_reference::type' {aka 'MyClass'}
return *p;
^
/usr/local/include/Wt/cpp17/any/any.hpp

I tried to get && but yet does not work. I need your assistance to solve the problem.

Thanks in advance.

Gokhan

    (1-2/2)