[Solved] how to filter dictionary terms in category view? (QcomboBox)
-
i m trying to make a dictionry type software. This sofware will be the desktop version of this site http://technologybasic.com/. This site has many technology terms and show the terms in catagory wise.
Look at the application-
!http://technologybasic.com/desktop-apps/catagory-filter-from-database.jpg(Catagory problem)!
Already i do most of the work. but failed to do filtering terms in catagory view from the database. I don't know how to do it.
I show all the terms title in Qlistwidget from the database. but this terms has 5 catagory.
internet
software
hardware
bit
technicali have also load this terms in the comboBox. if i change the terms in the comboBox..it will filter the terms Title list in category wise.
Please take the "souce code":http://technologybasic.com/desktop-apps/sourcecodeTB.zip
Before compiling it first import in your Localhost "this MySQL database":http://technologybasic.com/desktop-apps/Database.sql.gz.
now i will give u a basic idea of mydatabase.
jos_content - title
introtext
catidjos_categories- cattitle
catid
i know if i query it,
@Select * from jos_content where catid="11"@it will show my internet terms. but how it will works in comboBox.
can u do the work for me? and give me the source code. cause i have no idea.
-
ok... now i got it :)
Use QSqlQueryModel":http://qt-project.org/doc/qt-4.8/qsqlquerymodel.html and set your filter query.
@
QSqlDatabase sqlDB = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("technolo");
db.setUserName(...);
db.setPassword(..);QSqlQuery query("SELECT * from jos_categories WHERE 'cattitle' LIKE %filter%", sqlDB); //"filter" is your entered text
sqlModel->setQuery( query ); //also triggers model reset -> view update
@ -
thanks raven-worx.
i m trying to solve the problem another way. Almost i have solved this....but one problem when i select Categories from comboBox, it filter successfully. but it shows previous categories terms.i mean if i select "FileFormat" terms, it shows fileformat terms succesfully. but when i select "Bits" terms, it shows FileFormat+ bits terms.
again i select hardware terms, it shows FileFormat+ bits+hardware terms.to solve the problem i use @ui->listwidget->clear(); @ but problem not solved.
To filter the terms i added this code -
@void MainWindow::on_comboBox_currentIndexChanged(int index)
{
QString abc= ui->comboBox->currentText();
ui->listWidget->clear();
QSqlQuery query3("select * from jos_content,jos_categories where catalias='"+abc+"' and jos_content.catid=jos_categories.catid");
QSqlRecord record2= query3.record();
while(query3.next())
{
CatFilVar<<query3.value(record2.indexOf("title")).toString();
}ui->listWidget->clear(); for(int i=0; i<CatFilVar.size();i++){ ui->listWidget->addItem(CatFilVar.at(i)); }
}@
here the latest "source code":http://technologybasic.com/desktop-apps/categoryproblemQt.zip.
database is same - http://technologybasic.com/desktop-apps/Database.sql.gz -
added one line
@void MainWindow::on_comboBox_activated(int index)
{
ui->listWidget->clear();
CatFilVar.clear(); //Just added this code.
QString abc= ui->comboBox->currentText();QSqlQuery query3("select * from jos_content,jos_categories where catalias='"+abc+"' and jos_content.catid=jos_categories.catid"); QSqlRecord record2= query3.record(); while(query3.next()) { CatFilVar<<query3.value(record2.indexOf("title")).toString(); } ui->listWidget->clear(); for(int i=0; i<CatFilVar.size();i++){ ui->listWidget->addItem(CatFilVar.at(i)); }
}@