Am 10.12.2012 10:01, schrieb Thomas McGuire:
Hi,

On Saturday 08 December 2012 20:18:50 Andy Mayer wrote:
Am 08.12.2012 19:25, schrieb Thomas McGuire:
On Saturday 08 December 2012 11:34:17 Andy Mayer wrote:
I have a question regarding the possibilty of reading the body of a
javascript function from c++. I want to create a DSL based on QML and I
have to read the body of a javascript function.

e.g.

QML:
    Item {
function action() { console.log("Got message:", msg)
            return "some return value"
} }

C++:
QDeclarativeEngine engine;
QDeclarativeContext context(&engine);

QDeclarativeComponent component(&engine,
QUrl::fromLocalFile("MyItem.qml")); QObject* qmlSpenat =
component.beginCreate(&context);

QString actionString=qmlSpenat->property("action");//??? it doesn't
work, anything else?
Should work with QMetaObject::invokeMethod().

Thanks for the answer, but I don't want to invoke the javascript method.
I want to read out the body of the javascript method from C++.

e.g.: If I have a Javascript method within a qml-file

function action() { var x=0; return x+2;}

the question is: Is it possible to get the body "var x=0; return x+2;"
as QString (or something else?) from C++ side?
Ah I see, that is quite an unusual usecase. Getting the function body as a
string from the C++ side is not possible. However, the other way around is
doable, you could pass the function body string from QML to C++, either with a
function call or with a property binding.
Something like
        myCppObj.passFunctionString(action.toString())
Assuming that passFunctionString() is a C++ function that takes a QString as
argument.

Regards,
Thomas


_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
ok I have it, thank you!

You are right, it is a quite unusual use case from implementation/runtime point of view. But I tried to use QML as a declaration mechanism for development of domain specific languages (see http://pvdev.wordpress.com/2012/06/04/custom-domain-specific-languages-with-qt-declarative-qml/). I think it would be a very efficient approach. For the most use cases of DSL-developing QML has the right syntax and with the qtcreator-editor an outstanding editor with syntax highlighting and code completion. There is also a parser and after QDeclarativeComponent::beginCreate() an object-tree. A lot of work is already done.

But for my DSL (declaration of a special petri net) I need the body of the javascript functions. The workaround looks quite interesting...

Another question: Are there any plans to build a Xtext/Xtend-clone for Qt?

Thanks again and regards
Andy
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to