How to populate a combobox using a Qvector
-
Guys,
I need again your help, I need to populate a combobox using a vector.
I have a screen where the User enters the data, these data are stored in a Qvector.
Now I need to populate a combobox with the data that Qvector.
Below is the code fill the Qvector:@QString IP;
QTextCharFormat textFormat;
IP = ui->Campo_Digitar_ip->text();
IP += "\n";
QTextCursor cursor(ui->textEdit->textCursor());
cursor.insertText(IP);
vetorIP.append(IP);@And as I have tried so far to fill the combobox
@while(vetorIP.operator !=(0))
{
ui->comboBox_IP_Cadastro->addItem(vetorIP);
}@ -
You can populate a combobox using "addItems":http://qt-project.org/doc/qt-5.0/qtwidgets/qcombobox.html#addItems which requires a "QStringList.":http://qt-project.org/doc/qt-5.0/qtcore/qstringlist.html
QStringList can be generated by "toList.":http://qt-project.org/doc/qt-5.0/qtcore/qvector.html#toList -
Hi,
You should rather use something like:
@
foreach (const QString& ip, vectorIP) {
ui->comboBox_IP_Cadastro->addItem(ip);
}
@Hope it helps
EDIT: koahnig's solution is even more elegant
-
Guys,
I appreciate the help I ended up studying the documentation I saw that it was easier to fill the combobox with a QStringList.
I only have a problem in making information appear in another Dialog, the first screen have a combobox and a button to enter the "IPS", after that I have a screen to add the "IPS".
I just can not get the screen information for inclusion in the main screen, attached is an example of the code.
It would be possible to show me where I'm wrong?
https://docs.google.com/file/d/0BwQ4G9j5uY1JUzdfSFlrYTV5V2s/edit?usp=sharing