I want to save a number with a QLineEdit that is hidden from the users. I just want to use it for my programing.
In the Visual Basic 6 we have "Tag" property with textbox that can save any value in it as a temporary value.
I want to save a number with a QLineEdit that is hidden from the users. I just want to use it for my programing.
In the Visual Basic 6 we have "Tag" property with textbox that can save any value in it as a temporary value.
QLineEdit
is a QWidget
which is a QObject
. Every QObject
has the ability to store custom properties. It's worth checking the QObject
documentation here.
You can set custom properties with:
bool QObject::setProperty(const char* name, const QVariant& value)
and you can access custom properties with:
QVariant QObject::property(const char* name) const
Note that they store the data as QVariant
s, so your type must be registered as a metatype via Q_DECLARE_METATYPE
and qRegisterMetaType
unless it's one of the built-in metatypes.
Though, honestly, I've never used dynamic properties like that. I usually find it simpler to store the widget and its related data side by side as normal variables.
you can use setData method to attach data to most QT objects.