Reputation: 141
I'm trying to fill the combobox in QT 5.7 using following code:
ui->comboBox_2->addItems([]() -> QStringList {
QDate date = QDate::currentDate();
int current_year = date.toString("yyyy").toInt();
QStringList year_list;
for (int i = 0; i <= 50; i++) {
year_list << QString::number(current_year - (50 - i));
}
return year_list;
});
But it gives me this error: no viable conversion from '(lambda at ..)' to 'const QStringList'
What's the problem?
Upvotes: 0
Views: 511
Reputation: 21
include () at the end of {} to explicitly call this lambda function.
Upvotes: 1
Reputation: 1021
addItems expects a QStringList, not a lambda that produces a QStringList, so you have to call your lambda to get the QStringList:
ui->comboBox_2->addItems([]() { ... }());
Upvotes: 1