Project

General

Profile

problem overloading AuthWidget::createRegistrationModel()

Added by Cassie Nicol over 10 years ago

I want to use my own extended RegistrationModel() to get finer control on the loginName. I tried overloading AuthWidget::createRegistrationModel(), but found it sets AuthWidget::registrationModel_ which is private and thus not visible to my child class. It might have worked if registrationModel_ was protected instead of private.

Would it be better to split createRegistrationModel() into registrationModel() and createRegistrationModel()? registrationModel() would basically be the code that is now in createRegistrationModel() with the exception that it would call createRegistrationModel() to return a new RegistrationModel().

I have some more testing to do, and I'll add to this string later.

Thanks,

Cassie Ellen


Replies (3)

RE: problem overloading AuthWidget::createRegistrationModel() - Added by Cassie Nicol over 10 years ago

There is a leak of RegistrationModel in AuthWidget. It gets created, but never

deleted. It looks like the ownership of RegistrationModel was intended to be in RegistrationView, but there are problems there too.

RegistrationView does not delete model_ in it's destructor. It does delete an existing model_ if setModel() is called more than once. That could be disasterous if the following sequence occurred:

registrationModel_ = createRegistrationModel();

w->setModel(registrationModel_);

...

w->setModel(registrationModel_);

which would cause AuthWidget::registrationModel_ to point to unallocated space.

That would promote the argument that AuthWidget should not contain a pointer to the object RegistrationModel which is passed to RegistrationView.

Unfortunately, AuthWidget::createUpdatePasswordView() also uses createRegistrationModel() so the logic for that would need to change as well.

Or since both views use the same RegistrationModel object, then ownership of that object makes more sense in AuthWidget. That would require the delete in ~AuthWidget, and removal of the delete from RegistrationView. No change to UpdatePasswordWidget would be required.

For now, my solution is to make AuthWidget::registrationModel_ protected instead of private, and have MyAuthWidget handle it appropriately.

RE: problem overloading AuthWidget::createRegistrationModel() - Added by Thomas Saquet over 10 years ago

Hey Cassie,

Same problem here, I already had a Wt fork for something else so I passed what I needed in protected.

protected: 
  AuthModel *model_;
  RegistrationModel *registrationModel_;
  Login& login_;

Maybe I am missing something, but I do not understand the "virtual" if the underlying attributes are private :)

Regards,

Thomas

RE: problem overloading AuthWidget::createRegistrationModel() - Added by Koen Deforche about 10 years ago

Hey,

The criticism is entirely correct. I've split the function as suggested.

I'ld rather not have you have to mess in the library!

Regards,

koen

    (1-3/3)