0

I am trying to develop an application in Wt, namely with the Dbo module and a QueryModel to show in a WTableView.

However, as I try to do this,

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);

In theory (I found a similar snipped on the web somewhere) this is good, but my compiler does not agree:

/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> >*

The error looks about the same as attic greek to me, could someone walk me through what is going on? Unfortunately there is no documentation for Dbo::QueryModel.

Further, is the Wt toolkit too old to use, unmaintained? Should I back away from using it now?

edit: I tried every type of std::make_shared(model) casting that would seem to make sense but then I get more attic greek:

/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);
      |                           ^
overscore
  • 513
  • 4
  • 15

1 Answers1

1

It seems you haven't much experience with std::shared_ptr (or smart pointers at all). Reading an introduction to smart pointers may be useful.

Basically, two methods exist to construct a shared pointer:

  1. std::shared_ptr constructor: constructs a new shared pointer for the provided raw pointer.

    dbo::QueryModel< dbo::ptr<medical_staff> > *model = new dbo::QueryModel< dbo::ptr<medical_staff> >();
    std::shared_ptr<dbo::QueryModel< dbo::ptr<medical_staff> > > sharedModel = std::shared_ptr(model)
    
  2. std::make_shared<T>: construct a new object of type T and wraps it in a std::shared_ptr

    std::shared_ptr<dbo::QueryModel< dbo::ptr<medical_staff> > > sharedModel = std::make_shared<dbo::QueryModel< dbo::ptr<medical_staff> > >();
    

Method two is shorter, and is therefore the preferred option most of the time, although there are some exceptions: When would I want to construct a shared pointer from a raw pointer

m7913d
  • 10,244
  • 7
  • 28
  • 56