Qt Creator create getters and setters without reference parameter
Unsolved
Qt Creator and other tools
-
When i use the "Create Getter and Setter Member Functions", the creator creates functions with reference parameters. Ie:
#include <QObject> #include "base.hpp" #include "car.hpp" class Technician : public QObject { Q_OBJECT public: explicit Technician(Base *base, Car *car, QString coordinates, QObject *parent = 0); Base *getBase() const; void setBase(Base *value); Car *getCar() const; void setCar(Car *value); QString getCoordinates() const; void setCoordinates(const QString &value); // Here it created reference parameter, but I want value parameter private: Base *base; Car *car; QString coordinates; }; #endif // TECHNICIAN_HPP
How to change it in Qt Creator?
-
Hi,
Why do you want to pass a copy of QString rather than a const reference ? QString is a non trivial class and doing a copy of it each time you call setCoordinates isn't what's best memory and performance wise.
-
Const reference requires initialize a variable, but I don't want it. I want to be able to do:
Technician tech = Technician(); tech.setCoordinates("Any coordinates");
instead of:
QString coord = "Any coordinates"; Technician tech = Technician(); tech.setCoordinates(coord);
-
Nothing wrong with calling
tech.setCoordinates("Any coordinates")
even if you are using aconst QString&
parameter