PDA

View Full Version : how to add a tagline to QListWidet addItem() along with the data?



Choti
2nd May 2016, 11:41
Hello everyone,

I am working with QListWidget and I am supposed to pass a string to my ListWidget using addItem.


I have a line ui->listwidget->addItem(QString::fromstdString(s2));

where as S2 consists of some values like 1 , 2 , 3 ........

Now I want my output on the screen as


The Output data:: 1
The Output data:: 2
........



How can I pass the string "The output data" to ListWidget.


It would be great help if someone can help me out.

Thank you

anda_skoa
2nd May 2016, 12:09
QString has a "+" operator that allows you to concatenate string into a new string.

Alternatively you can use QString::arg() to replace a placeholder in the fixed string with the runtime value from s2.

Cheers,
_

Choti
2nd May 2016, 14:53
It worked :) Thank you very much