QDataWidgetMapper does not work with QLabels

I use QDataWidgetMapper to map data to QLineEdit and it works great. When I use to map data in QLabel, it does not show any data in the shortcut. I am trying to do it like this:

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 get the values ​​from the list and attach the list to the QDataWidgetMapper, from the mapping I use addMapping to add it to the text fields. Can someone tell me why it is not working with qLabels.

+5
source share
1 answer

By default, each widget uses a user property to transfer data between the model and widgets. QLabel does not have user rights. You should use the addMapping() extra function, which allows you to use a named property instead of the default user property.

 testMapper->addMapping(ui->label,3,"text"); 
+13
source

Source: https://habr.com/ru/post/1211774/


All Articles