Project

General

Profile

HowTo bind Wt::WStandardItemModel->itemChanged()

Added by Fabian V almost 5 years ago

Hi!

The documentation says WtStandardItemModel::itemChanged(): The item that has changed is passed as the first parameter.

I declared a function called:

void updatePublishings(Wt::WStandardItem *item);

And I tried to connect it:

model->itemChanged().connect(std::bind(&PublishingsModel::updatePublishings, this)); 

But I always get compilation errors:

Wrong number of arguments for pointer-to-member.

It only works when I bind to this function:

void updatePublishings();

But how can I get the changed-item-data?


Replies (3)

RE: HowTo bind Wt::WStandardItemModel->itemChanged() - Added by lm at almost 5 years ago

I think this is because you're not passing the parameter to updatePublishings:

std::bind(&PublishingsModel::updatePublishings, this, std::placeholders::_1)

But I think you could simply change to:

model->itemChanged().connect(this, &PublishingsModel::updatePublishings);

RE: HowTo bind Wt::WStandardItemModel->itemChanged() - Added by Fabian V almost 5 years ago

Thank you so much for the quick response.

This solution works great:

model->itemChanged().connect(std::bind(&PublishingsModel::updatePublishings, this, std::placeholders::_1));

But this get errors:

model->itemChanged().connect(this, &PublishingsModel::updatePublishings);

For me it's ok so. In case you want to know what's the error:

no matching function for call to ‘Wt::Signals::Signal<Wt::WStandardItem*>::connect(Wt::Signals::Impl::ConnectHelper<1, Args ...>::connect(Wt::Signals::Signal<Args ...>&, T*, void (V::*)(B1)) [with T = PublishingsModel; V = PublishingsModel; B1 = Wt::WStandardItem*; An = {}; Args = {Wt::WStandardItem*}; Wt::Signals::connection = Wt::Signals::Impl::Connection]::<lambda(Wt::WStandardItem*)>, PublishingsModel*&)’
       }, target);
                ^
../thirdparty/wt/include/Wt/Signals/signals.hpp:193:14: note: candidate: Wt::Signals::Impl::Connection Wt::Signals::Impl::ProtoSignal<Args>::connect(Wt::Signals::Impl::ProtoSignal<Args>::CbFunction&&, const Wt::Core::observable*) [with Args = {Wt::WStandardItem*}; Wt::Signals::Impl::ProtoSignal<Args>::CbFunction = std::function<void(Wt::WStandardItem*)>]
   Connection connect(CbFunction &&cb,
              ^~~~~~~
../thirdparty/wt/include/Wt/Signals/signals.hpp:193:14: note:   no known conversion for argument 2 from ‘PublishingsModel*’ to ‘const Wt::Core::observable*’

RE: HowTo bind Wt::WStandardItemModel->itemChanged() - Added by lm at almost 5 years ago

Right. The documentation doesn't say so, but it appears that the object has to be a Wt::Core::observable :shrug:.

    (1-3/3)