Results 1 to 4 of 4

Thread: Two way data map?

  1. #1

    Default Two way data map?

    I am fairly new to QT so I have what might be an easy question.

    I have a QComboBox that needs to be populated by a table in my database. I would like to be able to programmatically select the combo box by the table ID from the database. Of course the combobox index does not match the table ID's. To solve that problem I created QMap<TableID, ComboBoxIndex>. Now I can programmatically select the correct value in the combo box by using the map. However, I don't know how to do a "reverse" map to get the TableID by looking at the ComboBoxIndex. Arrrr. Is this possible? Am I not approaching this correctly?

    thanks.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Two way data map?

    You could use an SQL model directly in the QComboBox or even use a QDataWidgetMapper.
    J-P Nurmi

  3. #3

    Default Re: Two way data map?

    At one point I had an SQL model directly attached, but I couldn't get at the table ID of the model. The displayed text in the combo box came from column 1 and the table ID was in column 0. Is there a way to get at the table ID in column 0 that I can't figure out?.... I just found a way, but it is ugly. Here it is...is there a better way?

    Qt Code:
    1. int row = ui.comboBox->currentIndex();
    2. QModelIndex idx = ui.comboBox->model()->index(row, 0);
    3.  
    4. int id = ui.comboBox->model()->data(idx).toInt();
    5. qDebug() << id;
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Two way data map?

    Quote Originally Posted by chimby View Post
    At one point I had an SQL model directly attached, but I couldn't get at the table ID of the model. The displayed text in the combo box came from column 1 and the table ID was in column 0. Is there a way to get at the table ID in column 0 that I can't figure out?
    See QComboBox::setModelColumn().
    J-P Nurmi

Similar Threads

  1. Best way to display lots of data fast
    By New2QT in forum Newbie
    Replies: 4
    Last Post: 16th October 2008, 22:46
  2. Replies: 7
    Last Post: 29th August 2008, 10:24
  3. Replies: 4
    Last Post: 19th October 2007, 19:47
  4. Data model
    By steg90 in forum Qt Programming
    Replies: 3
    Last Post: 17th September 2007, 12:14
  5. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53

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.