Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QDataWidgetMapper not working with QLabels

Tags:

qt

qt4

qt-creator

I am using QDataWidgetMapper to map data to a QLineEdit and it works fine. When I use to map data to a QLabel it does not show any data in the label.I am trying to do it in the following way:

QDataWidgetMapper *testMapper=new QDataWidgetMapper();

testMapper->setOrientation(Qt::Vertical);
testMapper->setModel(testModel);


//setting the mapper values to the textboxes ----works fine
testMapper->addMapping(ui->LineEdit1,0);
testMapper->addMapping(ui->LineEdit2,1);

//setting it to qlabels
testMapper->addMapping(ui->label,3);----- does not work
testMapper->toFirst();

I am getting the values from the list and attaching the list to the QDataWidgetMapper, from the mapper I am using addMapping to append it to the textboxes. Could anyone let me know why it does not work with qLabels.

like image 341
Valla Avatar asked Jan 23 '15 16:01

Valla


1 Answers

By default, each widget's user property is used to transfer data between the model and the widget. QLabel has no user property. You should use an additional addMapping() function enables a named property to be used instead of the default user property.

testMapper->addMapping(ui->label,3,"text");
like image 67
Meefte Avatar answered Sep 19 '22 06:09

Meefte