【问题标题】:Wt++ TableView and QueryModelWt++ TableView 和 QueryModel
【发布时间】: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) );

【问题讨论】:

    标签: c++ mysql web wt


    【解决方案1】:

    Wt::WTableView::setModel 需要一个共享指针,即std::shared_ptr&lt;Wt::WAbstractItemModel&gt;,而不是指向您的项目模型的原始指针。

    所以,你应该替换

    auto *modelDataTable = new Wt::Dbo::QueryModel<Wt::Dbo::ptr<Utente>>();
    

    通过

    auto modelDataTable = std::make_shared<Wt::Dbo::QueryModel<Wt::Dbo::ptr<Utente>> >();
    

    请注意,这正是您的错误消息告诉您的内容:

    没有已知的参数 1 从 std::remove_reference&lt;Wt::Dbo::QueryModel&lt;Wt::Dbo::ptr&lt;Utente&gt; &gt;*&amp;&gt;::type {aka __Wt::Dbo::QueryModel&lt;Wt::Dbo::ptr&lt;Utente&gt; &gt;*} 到 const std::shared_ptr&lt;Wt::WAbstractItemModel&gt;&amp; 的转换

    (尝试重新阅读错误信息,以便下次理解)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-16
      • 1970-01-01
      • 1970-01-01
      • 2014-05-27
      • 1970-01-01
      • 2013-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多