Unsolved Why addMapping doesn't work?
-
Hi.
I have LineEditEx class inherited from QLineEdit. This class has property declared with this code:Q_PROPERTY(QString guid READ guid WRITE setGuid NOTIFY guidChanged)
When I try to assing some value to guid in usual way everything works fine and:
lineEditEx->guid="sdfsd";
and then I can read assigned value:
qDebug() << lineEditEx->getGuid();
But when I try to add mapping my code doesn't work properly and I don't know why, this code works:
mapper->addMapping(ui->lineEditEx, model->fieldIndex("_id"));
but this code doesn't work:
mapper->addMapping(ui->lineEditEx, model->fieldIndex("_id"), "guid");
-
Hi @Vladislav-Lisovenko ,
QMap<QString, int> map;
map->addMApping(string, int);It takes only key and value. only 2 parameters.
But in your case mapper->addMapping(ui->lineEditEx, model->fieldIndex("_id"), "guid");
It's 3 inside. So it won't accept.And from you code mapper->addMapping(ui->lineEditEx, model->fieldIndex("_id"), "guid");
What will you get from the key ui->lineEdit? -
@Ni.Sumi http://doc.qt.io/qt-5/qdatawidgetmapper.html#addMapping-1
I want to store some guid in lineEdit. -
Hi @Vladislav-Lisovenko ,
Sorry, I thought that you are using QMap , but yes addMapping is from QDatawidgetMapper .
AFAIK, QLinedit widget has user proeprty by default. How can you give this "guid" to line Edit ? But you can send this "guid" to the widgets like QLabel.
-
@Ni.Sumi I merely want to store hidden data, got from model, in lineEdit-widget.
-
Hi,
From your code, it doesn't seem that you have implemented the property properly.
You seem to be using a variable named
guid
that you have deemed the getter in your Q_PROPERTY declaration thusgetGuid
isn't the getter.For variable names, I'd recommend using a prefix like
_
to ensure there's no confusion. -
@SGaist Hi
Getter for guid exists, but this code also doesn't work:Q_PROPERTY(QString guid READ getGuid WRITE setGuid NOTIFY guidChanged)
Maybe I don't need Q_PROPERTY? But also when I comment line "Q_PROPERTY,,, " It doesn't work. I just need to map some hidden information to widget. I suppose problem not with Q_PROPERTY, problem with addMapping function.
-
Silly question but is
ui->lineEditEx
really a LineEditEx ? -
@SGaist Yes, of course ;). Code
ui->lineEdit-setGuid("sdfsdf"); qDebug() << ui->lineEdit-getGuid();
works perfectly.
-
Can you show how you setup your model and the mapper ?