Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
Qt fo MCUs 2.5.2
Description
Add mode to QUL Property so it manages the lifecycle (creation, usage and destruction) of object value s as a black box. Ex, it can be used as a view for the std:string, but it does not manage the lifecycle of std:string.
Example code:
#ifndef MAIN_H #define MAIN_H #include <qul/object.h> #include <qul/property.h> #include <cstring> #include <string> struct MyObject : public Qul::Object { Qul::Property<std::string> variable; MyObject() { variable.setValue("Hello World!"); const char *myString = variable.value().c_str(); m_myString = foo(myString); Qul::PlatformInterface::log("string is %s: ", m_myString.data()); } static std::string foo(const char* data) { return data; } std::string m_myString;; }; #endif // MAIN_H
This would be important for example in the use case where property is used for storing an IP address passed to the IP stack - you really don't know how long the pointer has to be alive, and when std::string is in property there is very little control over buffer. So, QML code accessing the property can cause buffer reallocation and hence a dangling pointer.