【发布时间】:2021-04-06 01:19:46
【问题描述】:
tableView 和 queryModel 有问题 这是我的错误:
lo.C: In constructor ‘HelloApplication::HelloApplication(const Wt::WEnvironment&)’:
hello.C:162:48: error: no matching function for call to ‘Wt::WTableView::setModel(std::remove_reference<Wt::Dbo::QueryModel<Wt::Dbo::ptr<Utente> >*&>::type)’
tableView->setModel( std::move(modelDataTable) );
^
In file included from hello.C:30:0:
/usr/local/include/Wt/WTableView.h:94:16: note: candidate: virtual void Wt::WTableView::setModel(const std::shared_ptr<Wt::WAbstractItemModel>&)
virtual void setModel(const std::shared_ptr<WAbstractItemModel>& model)
^
/usr/local/include/Wt/WTableView.h:94:16: note: no known conversion for argument 1 from ‘std::remove_reference<Wt::Dbo::QueryModel<Wt::Dbo::ptr<Utente> >*&>::type {aka Wt::Dbo::QueryModel<Wt::Dbo::ptr<Utente> >*}’ to ‘const std::shared_ptr<Wt::WAbstractItemModel>&’
这是一个 Utente 类:
class Utente
{
public:
Utente();
std::string nome;
std::string cognome;
template<class Action>
void persist(Action& a)
{
dbo::field(a, nome, "nome");
dbo::field(a, cognome, "cognome");
}
~Utente();
};
这段代码在应用程序类里面:
auto *modelDataTable = new Wt::Dbo::QueryModel<Wt::Dbo::ptr<Utente>>();
modelDataTable->setQuery(session.query<Wt::Dbo::ptr<Utente>>("select utente from utente Utente"));
modelDataTable->addAllFieldsAsColumns();
auto tableView = root()->addWidget(std::make_unique<Wt::WTableView>() );
tableView->setModel( std::move(modelDataTable) );
【问题讨论】: