QtComboBox issue with data
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.
Code:
// 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 :)
Re: QtComboBox issue with data
The code looks ok, the problem is probably elsewhere in your code.
By the way, you can replace the for loop with:
Code:
for(int i=0; i<80; ++i) {
comboPortFilter
->addItem
(QString("%1").
arg(i
+1,
2,
10,
'0'), i
+1);
}