Results 1 to 4 of 4

Thread: ComboBox with QSqlTableModel

  1. #1
    Join Date
    Oct 2007
    Posts
    9
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default ComboBox with QSqlTableModel

    I filled combobox with model like this
    cityModel = new QSqlTableModel(this);
    cityModel->setTable("cities"); // (city_id, city_name)
    cityModel->select();
    comboBox_city->setModel(cityModel);
    comboBox_city->setModelColumn(1);
    comboBox_city->setCurrentIndex(0);

    I can get current city_id with currentIndexChanged signal.
    How can i get city_id from comboBox any time without signal?

  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: ComboBox with QSqlTableModel

    May I ask how did you find out QComboBox::currentIndexChanged()? From docs? There is also QComboBox::currentIndex() and QComboBox::setCurrentIndex()..
    Qt Code:
    1. int idx = comboBox_city->currentIndex();
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Oct 2007
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ComboBox with QSqlTableModel

    I didn't find from docs. It is too complex just for me now. I asked here in the newbie forum and someone helped me.
    I am just trying to make a real application from QtDemos with model->copyPaste for now.
    I developed this solution. It took my two hours.

    QVariant city_id = cityModel->data(cityModel->index(comboBox_City->currentIndex(),0) );
    Last edited by mkarakaplan; 9th November 2007 at 23:34.

  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: ComboBox with QSqlTableModel

    No worries, luckily the documentation of Qt is great! A special application, Qt Assistant is provided together with Qt. The "index" tab of Qt Assistant is awesome. Just try to write for example "currentIndex" into index-tab and you'll see. Oh, and the same documentation also available online.
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    mkarakaplan (10th November 2007)

Similar Threads

  1. [Qt 4.3.1]A problem with combobox style
    By Tamara in forum Qt Programming
    Replies: 3
    Last Post: 19th September 2007, 10:49
  2. Replies: 8
    Last Post: 15th May 2007, 09:21
  3. Combobox Signals
    By b1 in forum Qt Programming
    Replies: 3
    Last Post: 1st August 2006, 10:21
  4. Filling combobox from database
    By Philip_Anselmo in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2006, 17:53
  5. QSqlTableModel
    By raphaelf in forum Qt Programming
    Replies: 4
    Last Post: 4th March 2006, 12:35

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.