diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-09-30 07:55:46 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-09-30 07:55:46 +0200 |
commit | 7af97fa4136d66bbad6c7907de6e7bd823de2e43 (patch) | |
tree | 94123be1810104d257aa50fe4b387dd8a1bf2a6c /examples/samplebinding | |
parent | 3bbcb7b0e6e0342569aa155d695bca46a7459eb0 (diff) | |
parent | ff792fd2e6842b990aff61a4e953dab5efbd89ae (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: I13721e13d2fab13945385fe529afe4ab431e0532
Diffstat (limited to 'examples/samplebinding')
-rw-r--r-- | examples/samplebinding/README.md | 13 | ||||
-rw-r--r-- | examples/samplebinding/bindings.xml | 1 | ||||
-rw-r--r-- | examples/samplebinding/main.py | 2 | ||||
-rw-r--r-- | examples/samplebinding/truck.cpp | 5 | ||||
-rw-r--r-- | examples/samplebinding/truck.h | 2 |
5 files changed, 22 insertions, 1 deletions
diff --git a/examples/samplebinding/README.md b/examples/samplebinding/README.md index 85e96ddbe..e84d1eff4 100644 --- a/examples/samplebinding/README.md +++ b/examples/samplebinding/README.md @@ -62,6 +62,19 @@ and the `clone()` and `addIcecreamFlavor(Icecream*)` need additional info about who owns the parameter objects when passing them across language boundaries (in this case C++ will delete the objects). +The `Truck` has getters and setters for the string `arrivalMessage`. +In the type system file, we declare this to be a property in Python: + +``` +<property type="std::string" name="arrivalMessage" get="getArrivalMessage" set="setArrivalMessage"/> +``` + +It can then be used in a more pythonic way: + +``` +special_truck.arrivalMessage = "A new SPECIAL icecream truck has arrived!\n" +``` + After shiboken generates the C++ code and CMake makes an extension module from the code, the types can be accessed in Python simply by importing them using the original C++ names. diff --git a/examples/samplebinding/bindings.xml b/examples/samplebinding/bindings.xml index f08243694..9be9f1afa 100644 --- a/examples/samplebinding/bindings.xml +++ b/examples/samplebinding/bindings.xml @@ -70,6 +70,7 @@ <value-type name="Truck"> <!-- Same ownership caveat applies here. --> + <property type="std::string" name="arrivalMessage" get="getArrivalMessage" set="setArrivalMessage"/> <modify-function signature="addIcecreamFlavor(Icecream*)"> <modify-argument index="1"> <define-ownership owner="c++"/> diff --git a/examples/samplebinding/main.py b/examples/samplebinding/main.py index bd1d10b8e..dc727c5d8 100644 --- a/examples/samplebinding/main.py +++ b/examples/samplebinding/main.py @@ -92,7 +92,7 @@ if __name__ == '__main__': del truck print("") - special_truck.setArrivalMessage("A new SPECIAL icecream truck has arrived!\n") + special_truck.arrivalMessage = "A new SPECIAL icecream truck has arrived!\n" special_truck.arrive() special_truck.addIcecreamFlavor(Icecream("SPECIAL *magical* icecream")) special_truck.printAvailableFlavors() diff --git a/examples/samplebinding/truck.cpp b/examples/samplebinding/truck.cpp index 6e24bdc87..056abfcd6 100644 --- a/examples/samplebinding/truck.cpp +++ b/examples/samplebinding/truck.cpp @@ -114,6 +114,11 @@ void Truck::setArrivalMessage(const std::string &message) m_arrivalMessage = message; } +std::string Truck::getArrivalMessage() const +{ + return m_arrivalMessage; +} + bool Truck::deliver() const { std::random_device rd; diff --git a/examples/samplebinding/truck.h b/examples/samplebinding/truck.h index 02e304a82..3f213f9ac 100644 --- a/examples/samplebinding/truck.h +++ b/examples/samplebinding/truck.h @@ -71,7 +71,9 @@ public: void leave() const; void setLeaveOnDestruction(bool value); + void setArrivalMessage(const std::string &message); + std::string getArrivalMessage() const; private: void clearFlavors(); |