PDA

View Full Version : How to build a search tool bar like Wireshark



leinad
28th January 2020, 20:07
Hi,

I know this is a broad question. If anyone is familiar with Wireshark, I was wondering how to build a search tool bar using that method.

What I would like is to build a query tool using a line editBox or something similar which as users type attribute names and a drop down list is is displayed which they can select from (kind of like a combobox). Next they would enter a value followed by a Boolean operator which concatenates multiple requests accordingly. The thing is the parsing of the input data appears to be calculated. Here is an example.

(ABC.agh > 3 && DEF.gju <= 245.0) OR mmn.kkjds != 100

So essentially as a user types AB, they get a drop down list such as ABC, ABD, ABL, etc. After they select "ABC.", they get a new list of attributes associated with ABC which in the above case is agf, etc. Once all is entered I need to parse across and evaluate the query.

I'm just wondering if there is a clever way of doing this may be not an lineEdit Widget, perhaps something different?

Any help would be appreciated? Could there is a library for this already?

Thanks!

d_stranz
29th January 2020, 00:37
Could there is a library for this already?

Check out QCompleter. It can at least handle the ABC -> ABCD ABCE ABDF... part. You may be able to combine that with a QValidator that uses regular expressions to ensure the search string is a valid Boolean expression.

leinad
29th January 2020, 14:00
I'm very familiar with QCompleter but it may help with the search at least partially but how do I add new attributes as I go along in the equation? What is the best widget for this, lineEdit?

d_stranz
29th January 2020, 17:29
I was thinking about this some more. I downloaded the Wireshark source code and it looks like the UI is written using Qt. From what I can see there are two classes in the ui/qt directory which might implement the search feature you are talking about: capture_filter_edit.[h, cpp] and capture_filter_syntax_worker.[h, cpp]. The class CaptureFilterEdit is derived from SyntaxLineEdit, which is derived from QLineEdit. At the core is a QCompleter, which works off a QStringList model of tokens, along with a QThread that examines the text for syntax.

It's pretty complex code, but you might take a look to see if there is anything you can learn from it.

leinad
31st January 2020, 13:44
I do have the Wireshark code but couldn't quite find where they did that functionality. Thanks for your help. I look through it and see if I can get ideas.

d_stranz
31st January 2020, 17:59
Check out the files I mentioned - they seem like a logical place for that functionality.