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. [Solved] how to filter dictionary terms in category view? (QcomboBox)
QtWS25 Last Chance

[Solved] how to filter dictionary terms in category view? (QcomboBox)

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.8k 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
    Mashpy
    wrote on last edited by
    #1

    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
    technical

    i 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
    catid

    jos_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.

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      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
      @

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

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

        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

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Mashpy
          wrote on last edited by
          #4

          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));
          }
          

          }@

          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