[Qt-interest] Implementing a dynamic expression at runtime

Alan M. Carroll amc at network-geographics.com
Thu Mar 5 15:13:12 CET 2009


You might find the Spirit Parser Generator interesting for this project.

http://spirit.sourceforge.net/

Writing an expression evaluator should be simple give the limited domain. Note that you can name your QObjects and then use findChild() to locate a specific object by name.

At 07:15 AM 3/5/2009, Donal wrote:
>Hi There,
>
>I want to enable a user to choose rules dynamically, for example if the Coolant Temperature and Engine RPM
>are monitored in real time (4 samples a second), I want to allow the user to say produce an alert
>when for example, "If coolantTemp < 40 AND engineRPM > 4500" alert the user with a dialog message.
>
>So I am wondering which is the best way to implement such dynamic logic. As far as I know C++ doesn't allow you to evaluate 
>dynamic code at run time.
>I have looked at QtScript and it seems to be able to interact with objects of QObject derived type.
>
>My idea is to construct a string such as "If 010C < 40 AND 010D > 60", where the 01n are the identifiers for the sensors.
>Then parse this string and construct some qscript logic from it to evaluate to true or false.
>Reason I'd like to store as QString is to allow the storing of rules to a file.




More information about the Qt-interest-old mailing list