0

私のコンストラクターでは、Sqlite データベースに接続し、そこから "Categories" ( QStrings) を読み取ります。私はそれらをに保管しますQList。それらが空かどうかをデバッガーで確認しましたが、すべて問題ありません。

私のint currCategoryIndexイニシャライザリストでは 0 に設定されています。そして、QComboboxesインデックス作成を 0 から開始するため、最初の項目にする必要があります。

私のコンストラクタからの抜粋:

dm.readDB_C(c_list); //reads into c_list
if(c_list.count() > 0) //has 1 or more items
    updateCategories();

これは、データベースを読み取り、空かどうかを確認し、そうでない場合は、これらのカテゴリを に追加する関数を呼び出す部分QComboBoxです。

updateCategories()関数 :

void MainWindow::updateCategories()
{
    for(int i = 0; i < c_list.count(); i++){

        if(ui->cmbCategory->findText(c_list[i]) != -1){ //-1 means "not found"
            continue;
        } else {
            ui->cmbCategory->addItem(c_list[i]); //Add to QCombobox
        }
    }
    ui->cmbCategory->setCurrentIndex(currCategoryIndex); //Should be the first item
}

QCombobox にすべての項目がありますが、何も選択されていません。ボックスをクリックして、自分で選択する必要があります。それは起こるはずがありません。

なにが問題ですか?なぜそれ自体を選択しないのですか?

編集:

currentIndexChanged信号:

void MainWindow::on_cmbCategory_currentIndexChanged(int index){
    currCategoryIndex = index;
}
4

1 に答える 1