Results 1 to 2 of 2

Thread: QtComboBox issue with data

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

    Qt Code:
    1. comboPortFilter = new QComboBox();
    2. comboStatusFilter = new QComboBox();
    3.  
    4. // COMBO 1
    5. comboPortFilter->addItem("All");
    6. for(int i = 0; i < 80; i++){
    7. char c[10];
    8. memset(c, 0, sizeof(c));
    9. sprintf(c, "%02i", i + 1);
    10. comboPortFilter->addItem(c, i + 1);
    11. }
    12.  
    13. // COMBO 2
    14. comboStatusFilter->addItem("All", 0);
    15. comboStatusFilter->addItem("Green (no errors)", 1);
    16. comboStatusFilter->addItem("Amber (possible errors)", 2);
    17. comboStatusFilter->addItem("Red (definite errors)", 3);
    18. comboStatusFilter->addItem("Unknown", 4);
    To copy to clipboard, switch view to plain text mode 

    I can easily find a work around in this case but if I am not using the QComboBox api properly I would rather know
    Last edited by aatwo; 12th September 2011 at 10:10.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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:
    Qt Code:
    1. for(int i=0; i<80; ++i) {
    2. comboPortFilter->addItem(QString("%1").arg(i+1, 2, 10, '0'), i+1);
    3. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QTableView massive model data updates issue
    By cyberbob in forum Newbie
    Replies: 3
    Last Post: 7th December 2010, 23:09
  2. Replies: 0
    Last Post: 14th June 2010, 22:37
  3. Replies: 1
    Last Post: 28th March 2010, 05:52
  4. Replies: 0
    Last Post: 15th May 2009, 15:12
  5. Replies: 3
    Last Post: 4th July 2006, 10:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.