PDA

View Full Version : QtComboBox issue with data



aatwo
12th September 2011, 10:03
Hey guys. I have two QComboBox's and I am initialising them using the constructor that lets you set both the text and the QVariant data item for each element. Problem is it is working for one of the combo boxes but not the other. In the second combo box every data item for each element is zero no matter what I try (even if I set it explicitly using the set item function), while at the same time every piece of data in the first combo box is exactly as I expect.

Is there something I am missing here?

Kind regards, Aaron.



comboPortFilter = new QComboBox();
comboStatusFilter = new QComboBox();

// COMBO 1
comboPortFilter->addItem("All");
for(int i = 0; i < 80; i++){
char c[10];
memset(c, 0, sizeof(c));
sprintf(c, "%02i", i + 1);
comboPortFilter->addItem(c, i + 1);
}

// COMBO 2
comboStatusFilter->addItem("All", 0);
comboStatusFilter->addItem("Green (no errors)", 1);
comboStatusFilter->addItem("Amber (possible errors)", 2);
comboStatusFilter->addItem("Red (definite errors)", 3);
comboStatusFilter->addItem("Unknown", 4);


I can easily find a work around in this case but if I am not using the QComboBox api properly I would rather know :)

wysota
12th September 2011, 14:04
The code looks ok, the problem is probably elsewhere in your code.

By the way, you can replace the for loop with:

for(int i=0; i<80; ++i) {
comboPortFilter->addItem(QString("%1").arg(i+1, 2, 10, '0'), i+1);
}