Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Issue of QComboBox:currentIndexChanged() and Model
QtWS25 Last Chance

Issue of QComboBox:currentIndexChanged() and Model

Scheduled Pinned Locked Moved General and Desktop
3 Posts 1 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mbnoimi
    wrote on last edited by
    #1

    Hello,

    QComboBox doesn't show currentIndex correctly after calling any method from its model; How can I fix this issue?

    [code]Requests::Requests(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Requests)
    {
    ui->setupUi(this);
    ui->comboBox_category->setModel(model_labCategoryList());
    ui->comboBox_category->setModelColumn(1);
    }

    QSqlQueryModel *Requests::model_labCategoryList() const
    {
    _model_labCategoryList->setQuery(query_selectAllCategories);
    return _model_labCategoryList;
    }

    void Requests::on_comboBox_category_currentIndexChanged(int index)
    {
    // current index of comboBox_category disappear here
    // When I comment the line below the GUI works fine
    int categoryId = _db->model_labCategoryList()->record(index).value("id").toInt();
    ui->spinBox->setValue(categoryId);
    }[/code]

    NOTE: on_comboBox_category_currentIndexChanged() works fine but the GUI doesn't show correctly!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbnoimi
      wrote on last edited by
      #2

      When I added this debug line:
      [code]void Requests::on_comboBox_category_currentIndexChanged(int index)
      {
      // current index of comboBox_category disappear here
      // When I comment the line below the GUI works fine
      int categoryId = _db->model_labCategoryList()->record(index).value("id").toInt();
      ui->spinBox->setValue(categoryId);
      qDebug() << "categoryId" << categoryId;
      }[/code]

      I got:
      [code]categoryId 0
      categoryId 1[/code]

      Really strange!!!

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mbnoimi
        wrote on last edited by
        #3

        I tried to use the following although the debug result is OK but the GUI still not working fine!

        [code] void Requests::on_comboBox_category_currentIndexChanged(int index)
        {
        if (index > -1) {
        // current index of comboBox_category disappear here
        // When I comment the line below the GUI works fine
        int categoryId = _db->model_labCategoryList()->record(index).value("id").toInt();
        ui->spinBox->setValue(categoryId);
        qDebug() << "categoryId" << categoryId;
        }
        }
        [/code]

        Debug:
        [code]categoryId 1[/code]

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved