PDA

View Full Version : QString in QtScript



ivareske
24th October 2010, 19:07
How can I use QStrings inside a QtScript? For instance:

QString script = " QString a = "abcd"; a.contains("cd"); "
QScriptEngine e;
QScriptValue res = e.evaluate( script );

Or is it only possible to use java code?

I`m making a program where the user can search for music by tags, and I want to make the users be able to script this. For instance
ARTIST.contains(" lady ") || ARTIST.contains( "gaga" ) && YEAR>2009; (stupid examle, but you get the idea)
I was thinking to first replace ARTIST (and other tags) by the a qstring with the tag value and then evaluate the script.

Any ideas how to do this?

wysota
24th October 2010, 19:42
Javascript (it's "Javascript" not "Java") has its own support for strings so you don't need QString (unless of course you really need it then you can use it freely).

tbscope
24th October 2010, 19:43
Use a javascript String.

http://www.w3schools.com/jsref/jsref_obj_string.asp

Edit: too late

ivareske
24th October 2010, 19:49
I meant javastring. By "unless of course you really need it then you can use it freely", you mean it is possible to use QString and it`s functions in QtScripts? If so, how do I do that? QString has a lot more convenient functions than javastring, so I would like to use QString if possible.

wysota
24th October 2010, 20:06
I meant javastring. By "unless of course you really need it then you can use it freely", you mean it is possible to use QString and it`s functions in QtScripts? If so, how do I do that? QString has a lot more convenient functions than javastring, so I would like to use QString if possible.

You need proper bindings that have to be generated using the QtScript binding generator available "somewhere" (it used to be on Qt Labs but apparently it's not there anymore, try searching on gitorious).

ivareske
25th October 2010, 17:32
Thanks, that looks like what I need! I`ll try it