【发布时间】:2020-10-16 01:56:57
【问题描述】:
我正在尝试在 Wt 中开发一个应用程序,即使用 Dbo 模块和 QueryModel 以显示在 WTableView 中。
但是,当我尝试这样做时,
dbo::QueryModel< dbo::ptr<medical_staff> > *model = new dbo::QueryModel< dbo::ptr<medical_staff> >();
model->setQuery(session_.find<medical_staff>());
model->addAllFieldsAsColumns();
Wt::WTableView *view = new Wt::WTableView();
view->setModel(model);
理论上(我在网上某处发现了类似的片段)这很好,但我的编译器不同意:
/home/phil/projects/TN-wt/src/view/StaffView.cxx:84:20: error: cannot convert ‘Wt::Dbo::QueryModel<Wt::Dbo::ptr<medical_staff> >*’ to ‘const std::shared_ptr<Wt::WAbstractItemModel>&’
84 | view->setModel(model);
| ^~~~~
| |
| Wt::Dbo::QueryModel<Wt::Dbo::ptr<medical_staff> >*
在我看来,这个错误与阁楼希腊语大致相同,有人可以告诉我发生了什么吗? 不幸的是,没有 Dbo::QueryModel 的文档。
此外,Wt 工具包是否太旧而无法使用,无法维护?我现在应该停止使用它吗?
编辑: 我尝试了所有类型的 std::make_shared(model) 转换,这似乎是有意义的,但后来我得到了更多的阁楼希腊语:
/home/phil/projects/TN-wt/src/view/StaffView.cxx:82:27: error: no matching function for call to ‘make_shared(Wt::Dbo::QueryModel<Wt::Dbo::ptr<medical_staff> >*&)’
82 | std::make_shared(model);
| ^
In file included from /usr/include/c++/9/memory:81,
from /usr/include/Wt/Core/observable.hpp:12,
from /usr/include/Wt/Core/observing_ptr_impl.hpp:10,
from /usr/include/Wt/Core/observing_ptr.hpp:136,
from /usr/include/Wt/WGlobal.h:11,
from /usr/include/Wt/WObject.h:11,
from /usr/include/Wt/WWidget.h:10,
from /usr/include/Wt/WCompositeWidget.h:10,
from /home/phil/projects/TN-wt/src/view/StaffView.h:3,
from /home/phil/projects/TN-wt/src/view/StaffView.cxx:1:
/usr/include/c++/9/bits/shared_ptr.h:714:5: note: candidate: ‘template<class _Tp, class ... _Args> std::shared_ptr<_Tp> std::make_shared(_Args&& ...)’
714 | make_shared(_Args&&... __args)
| ^~~~~~~~~~~
/usr/include/c++/9/bits/shared_ptr.h:714:5: note: template argument deduction/substitution failed:
/home/phil/projects/TN-wt/src/view/StaffView.cxx:82:27: note: couldn’t deduce template parameter ‘_Tp’
82 | std::make_shared(model);
| ^
【问题讨论】: