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. Search in Database with HTML Tags

Search in Database with HTML Tags

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.1k Views 2 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.
  • F Offline
    F Offline
    Fuel
    wrote on last edited by
    #1

    At the moment i have a QTextEdit with Text that can be formatted. The whole Text i save with HTML Tags in the Database in a Text Field. That works find, because i can load the Text from the Database an put it again in the QTextEdit and its formatted.

    The only Problem is now, that i want to search in that Field for Words and show the Result in a QTableView. It works by the Way, but if i search for Tags like head, body or other HTML Things, all Entrys will be shown.

    Is there a Possibility to search in that Fields and ignore the HTML Thing? Maybe some RegEx Code, but it sounds difficult in the first Moment. An easier Way would be to save the Plaintext in an extra Field, but that sounds dirty.

    Anyone has an idea?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      I think you can get pretty far with regular expressions
      alt text

      \b(\w+(?![^<>]*>))\b
      
      1 Reply Last reply
      0
      • F Offline
        F Offline
        Fuel
        wrote on last edited by
        #3

        The RegEx works nice, but i dont know how to implement it. This is what i try. QDebug always returns an empty string.

        QRegExp regex("\b(\w+(?![^<>]*>))\b");
                    regex.indexIn(query.value(1).toString());
                    QString str = regex.cap();
                    qDebug () << str;
                    if (str.contains(text))
                    {
                        QList<QString> row;
                        row.append(query.value(0).toString());
                        row.append(query.value(1).toString());
                        row.append(query.value(2).toString());
                        row.append(query.value(3).toString());
                        row.append(query.value(4).toString());
                        row.append(query.value(5).toString());
                        data.append(row);
                    }
        
        K 1 Reply Last reply
        0
        • F Fuel

          The RegEx works nice, but i dont know how to implement it. This is what i try. QDebug always returns an empty string.

          QRegExp regex("\b(\w+(?![^<>]*>))\b");
                      regex.indexIn(query.value(1).toString());
                      QString str = regex.cap();
                      qDebug () << str;
                      if (str.contains(text))
                      {
                          QList<QString> row;
                          row.append(query.value(0).toString());
                          row.append(query.value(1).toString());
                          row.append(query.value(2).toString());
                          row.append(query.value(3).toString());
                          row.append(query.value(4).toString());
                          row.append(query.value(5).toString());
                          data.append(row);
                      }
          
          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @Fuel

          QRegExp is the older version within Qt. It is better to start with QRegularExpression

          There is an example given which can help you also in testing different regular expression with some text.

          Vote the answer(s) that helped you to solve your issue(s)

          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