MrLoick / staff

Automatically exported from code.google.com/p/staff
Apache License 2.0
0 stars 0 forks source link

Create function Set mtpData pointer for Staff::Optional Staff:::nullable #226

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
We need this function only changes the reference "m_tpData" within class 
"optional :: staff" and "staff:nillable".

ex:
     //Do not use this function before you understand shared pointer(shared_ptr) concept 
     inline void Set (Type * val)
     {
        m_tpData.m_pCounter++;
        m_tpData.Set (val);
     } 

Thus manipulate objects within the form without the optional subject,
if not to assign an instance object "Person" in a "optional<Person>" object 
creating a new reference
Ex:
Person *a;
Optional< Person > b = a;
In this case a not equals b but use next example a equal b
Ex
Person *a;
Optional< Person > b.Set(a);

Other ex:
Class PersonForm {
  ...
  QPointer< Person > person;
  void findPeople()
  {
    person = personService->RetrieveByPk(call).RetrieveByPkResult.Get()
    this.SyntoView(person);
  }
  ...
}

Original issue reported on code.google.com by rafaelpi...@gmail.com on 30 Apr 2014 at 6:40

GoogleCodeExporter commented 8 years ago
Sorry for late response.

staff::Optional and staff::Nillable are intended as strong pointers, you must 
have instance of Optional or Nillable to hold and access the real object.

Regarding example code you provided:

1. QPointer (Qt's) can only hold objects which is inherited from QObject.

2. staff::Optional nor staff::Nillable can't hold classes derived from QObject, 
because QObject's are non-copyable (unless you only use Get operation).

3. QPointer is only guard to pointer, it does not destruct the object when it 
leave scope. 

After calling 
{{{
    person = personService->RetrieveByPk(call).RetrieveByPkResult.Get()
}}}

person will remain NULL, because temporary Optional object will be destructed 
after that line. And QPointer will set internal pointer to object to NULL. 
Really staff_codegen generated code even can't manage objects derived from 
QObject.

Original comment by loentar on 12 Sep 2014 at 7:22

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r875.

Original comment by loentar on 15 Oct 2014 at 8:05