What do you want - all of the items concatenated into a single string, or each item as a separate string in a list of strings?
To do the first:
//Get user inputs
int names = ui->listWidget->count();
for(int i = 0; i < names; i++)
{
allNamesInOneString += ui->listWidget->item(i)->text();
}
//Get user inputs
QString allNamesInOneString;
int names = ui->listWidget->count();
for(int i = 0; i < names; i++)
{
allNamesInOneString += ui->listWidget->item(i)->text();
}
To copy to clipboard, switch view to plain text mode
To do the second:
//Get user inputs
int names = ui->listWidget->count();
for(int i = 0; i < names; i++)
{
allNamesAsAList << ui->listWidget->item(i)->text();
}
//Get user inputs
QStringList allNamesAsAList;
int names = ui->listWidget->count();
for(int i = 0; i < names; i++)
{
allNamesAsAList << ui->listWidget->item(i)->text();
}
To copy to clipboard, switch view to plain text mode
Note that your original code attempts to retrieve one too many items from the list widget. List widget item indexes go from 0 to count() - 1, not count().
Bookmarks