Results 1 to 6 of 6

Thread: QString in QtScript

  1. #1
    Join Date
    Jul 2008
    Location
    Norway, Trondheim
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Post QString in QtScript

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QString in QtScript

    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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QString in QtScript

    Use a javascript String.

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

    Edit: too late

  4. #4
    Join Date
    Jul 2008
    Location
    Norway, Trondheim
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QString in QtScript

    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QString in QtScript

    Quote Originally Posted by ivareske View Post
    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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jul 2008
    Location
    Norway, Trondheim
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QString in QtScript

    Thanks, that looks like what I need! I`ll try it

Similar Threads

  1. QtScript
    By lamosca in forum Newbie
    Replies: 2
    Last Post: 20th May 2010, 23:01
  2. Replies: 4
    Last Post: 1st February 2010, 14:21
  3. Replies: 0
    Last Post: 25th November 2009, 07:46
  4. Replies: 4
    Last Post: 31st January 2008, 20:44
  5. how to copy part of QString to anothe QString
    By nass in forum Qt Programming
    Replies: 1
    Last Post: 26th March 2007, 19:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.