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] QSqlTableModel with two setFilter

[Solved] QSqlTableModel with two setFilter

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 8.4k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    jalomann
    wrote on last edited by
    #1

    @
    void ScooterWindow::UpdateQuery3(const QString &text, const QString &text2)
    {
    QString searchitem1 = text;
    QString searchitem2 = text2;

    ScooterWindow::model->setFilter(QString("name like '%%1%' AND description like '%%2%'").arg(searchitem1).arg(searchitem2));
    ScooterWindow::model->select();
    

    }
    @

    Can I separate setFilter queries on two lines?

    1 Reply Last reply
    1
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you mean something like

      @
      ("name like '%%1%' AND "
      "description like '%%2%'").arg(searchItem1)
      @

      ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jalomann
        wrote on last edited by
        #3

        That helps a little bit. I wanted to avoid using "AND". I want to build a query with filter for multiple columns (even more than two in my example) and then the line is not so "stylish" any more.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          In that case, you could make a "filter builder"

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jalomann
            wrote on last edited by
            #5

            My target is make filter for all colums of the table. I would probably need 5-6 columns. I have filter for first column in the picture.

            http://aijaa.com/mdEqaQ

            @query.exec(QString("SELECT * IN scooter WHERE name like %1%").arg(searchitem));
            @

            I would be more confident using this type of query but then my tableView doesn't get updated any more. I have seen examples where multiple WHERE sentences are presented line after line.

            Do you have practical example how should I implement this?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              I am not sure I am really following you here.

              Can you show me the example ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jalomann
                wrote on last edited by
                #7

                Sorry about the delay... I moved from a country to another and had to sort things out. I solved the problem like below. It is more or less formatting.

                @
                model->setFilter(QString("name like '%%1%' AND "
                "type like '%%2%' AND "
                "description like '%%3%'")
                .arg(searchitem1)
                .arg(searchitem2)
                .arg(searchitem3));
                @

                Following question:
                http://qt-project.org/forums/viewthread/31755/

                1 Reply Last reply
                1

                • Login

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