Returning C++ references from more programming interfaces?
-
@elfring, so you want programmers to replace Code 1 with Code 2; have I understood you correctly?
//====== // Code 1 //====== Example demo1; demo1.setData(123); // Automatically emits valueChanged() immediately //====== // Code 2 //====== Example demo1; notifier demo2(demo1, 123); // valueChanged() is emitted when demo2 is destroyed
I must say that Code 1 is a much more elegant and intuitive than Code 2.
-
so you want programmers to replace Code 1 with Code 2; …
Not really. - I suggest to choose between available software design options.
The standard behaviour of the function “QStandardItem::setData” is generally fine.
The software situaton might look different if more reference-returning functions from a container class like QVector will be taken into account.
A need can evolve to call the function “valueChanged” (or “dataChanged”) in a C++ destructor, can't it? -
@elfring said in Returning C++ references from more programming interfaces?:
so you want programmers to replace Code 1 with Code 2; …
Not really. - I suggest to choose between available software design options.
OK.
The standard behaviour of the function “QStandardItem::setData” is generally fine.
I'm glad you think it's generally fine.
The software situaton might look different if more reference-returning functions from a container class like QVector will be taken into account.
I already explained above why QStandardItem must not provide a reference to is internal data. Do you understand that explanation?
A need can evolve to call the function “valueChanged” (or “dataChanged”) in a C++ destructor, can't it?
No, it can't. The signal should be emitted immediately when the data is changed. It should not wait for the destructor of another struct/object.
-
Do you understand that explanation?
I can follow software development concerns (which were expressed here) to some degree.
The signal should be emitted immediately when the data is changed.
This expectation is also generally fine.
It should not wait for the destructor of another struct/object.
The available programming interfaces support to call desired functions in C++ destructors. You can choose under which circumstances such a software design approach will be appropriate.
-
@elfring said in Returning C++ references from more programming interfaces?:
I can follow software development concerns (which were expressed here) to some degree.
That's good. So please address those concerns. For example, why should Qt provide extensions that break encapsulation and increase the risk of errors?
The signal should be emitted immediately when the data is changed.
This expectation is also generally fine.
Good.
It should not wait for the destructor of another struct/object.
The available programming interfaces support to call desired functions in C++ destructors. You can choose under which circumstances such a software design approach will be appropriate.
I cannot see any circumstance where such a software design approach will be appropriate.
-
@elfring said in Returning C++ references from more programming interfaces?:
For example, why should Qt provide extensions that break encapsulation and increase the risk of errors?
I suggest to use algorithms which can work together with container classes at more source code places.
You did not address any of the concerns. You only added suggestions.
That is not acceptable. You must only submit ideas/proposals that don't break encapsulation.