Qt World Summit: Register Today!

Search in Database with HTML Tags

  • 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?

  • Lifetime Qt Champion

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


  • 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");
                QString str = regex.cap();
                qDebug () << str;
                if (str.contains(text))
                    QList<QString> row;

  • @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.

Log in to reply