-1

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.

Mat
  • 202,337
  • 40
  • 393
  • 406
mohsen amiri
  • 73
  • 1
  • 2
  • 7

2 Answers2

3

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 QVariants, 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.

cgmb
  • 4,284
  • 3
  • 33
  • 60
-1

you can use setData method to attach data to most QT objects.

M. Utku ALTINKAYA
  • 2,254
  • 23
  • 29
  • 1
    setData is a method on QGraphicsItem. It doesn't exist on QLineEdit, though setProperty is very similar. – cgmb May 05 '13 at 04:34