Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Embedded scripting language in Qt application
QtWS25 Last Chance

Embedded scripting language in Qt application

Scheduled Pinned Locked Moved General and Desktop
16 Posts 4 Posters 7.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 2 Offline
    2 Offline
    2beers
    wrote on last edited by
    #1

    Hi everyone. I'm currently in a research phase of building an application that will allow users to control objects using a scripting language, specially javascript.

    To give you a small example of what I'm trying to do is a drawing application.
    For example the user want to draw a circle with center in x,y , radius r and color c. Normally I can provide input fields for all this info and a push button to draw the object. But I want to provide an easy way to create 50 circles at different position without pushing the draw button 50 times. The best way I could think is using a scripting language(javascript). The user could do something like this:

    @
    //javascript code
    var y=10;
    var r=3;
    var c="#FF0000";
    for(i=0;i<50;i++){
    drawCircle(i+10,y,r,c);
    }@

    where the function drawCircle(x,y,r,c) should appellate drawCircleCPP(x,y,r,c) in C++(Qt)

    So what I'm looking, are some tutorials and more info about how should I implement this, what libraries do you recommend me, cause this is new to me and I need to start from something.

    Thanks

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Qt has the QtScript module. That is a good way to integrate javascript in your application.

      Drawing however is tricky in the way you imagine it.

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        ZapB
        wrote on last edited by
        #3

        As Andre say QtScript is the way to go here. Have a thorough read of the "scripting docs":http://doc.qt.nokia.com/latest/scripting.html.

        The key to solving this is in the choice of what objects to expose form the C++ side and the environment in which they operate. We have done this for controlling some hardware devices and also for controlling the analysis of data from scripts.

        Nokia Certified Qt Specialist
        Interested in hearing about Qt related work

        1 Reply Last reply
        0
        • 2 Offline
          2 Offline
          2beers
          wrote on last edited by
          #4

          wow! thanks Andre and ZapB. I knew about QtScript but I always taught it can only be used with QtWebkit only. This solves all my problems in a very easy and fast way.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            Qt script was there long before webkit entered Qt :-)

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              ZapB
              wrote on last edited by
              #6

              It's just that QtScript now happens to use the same JS backend as WebKit. Although this is likely to be replaced with the V8 JS engine in the future.

              Nokia Certified Qt Specialist
              Interested in hearing about Qt related work

              1 Reply Last reply
              0
              • 2 Offline
                2 Offline
                2beers
                wrote on last edited by
                #7

                [quote author="ZapB" date="1301566923"]It's just that QtScript now happens to use the same JS backend as WebKit. Although this is likely to be replaced with the V8 JS engine in the future.[/quote]

                It will be interesting to see how V8 will do. Probably will help a lot with large script files where you need to execute a lot of actions.

                1 Reply Last reply
                0
                • Z Offline
                  Z Offline
                  ZapB
                  wrote on last edited by
                  #8

                  True. I still try to stick all of the heavy lifting into the exposed C++ objects though. For what I have done so far I have not really had any performance problems with the JS-Core backend. Greater efficiency is always nice though. ;-)

                  Nokia Certified Qt Specialist
                  Interested in hearing about Qt related work

                  1 Reply Last reply
                  0
                  • 2 Offline
                    2 Offline
                    2beers
                    wrote on last edited by
                    #9

                    ok. I've read some of the info in the documentation and some examples I think I made a cleat idea about how to implement this, but I have a new question.

                    Is there a javascript editor widget that I could implement in my application> I want to be able to change colors, show line numbers , similar to the one that Qt Creator is using??

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #10

                      I have actually seen that around somewhere, yes.

                      1 Reply Last reply
                      0
                      • Z Offline
                        Z Offline
                        ZapB
                        wrote on last edited by
                        #11

                        I think that somebody on the qt-interest mailing list tried to extract the editor from qt-creator as a stand-alone component earlier this year or late last year. Have a search through the archives to see if you can find it.

                        Nokia Certified Qt Specialist
                        Interested in hearing about Qt related work

                        1 Reply Last reply
                        0
                        • 2 Offline
                          2 Offline
                          2beers
                          wrote on last edited by
                          #12

                          thanks again Andre and ZapB. So far the best thing that I found is this post on qtcentre: http://www.qtcentre.org/threads/25501-QtScript-script-text-editor-for-Qt-4.4.3-with-Syntax-Highlighter?p=121992#post121992

                          I'll try and search on qt-interest mailing list . Let me know if you find something.

                          1 Reply Last reply
                          0
                          • Z Offline
                            Z Offline
                            ZapB
                            wrote on last edited by
                            #13

                            This is the "thread":http://lists.qt.nokia.com/pipermail/qt-interest/2010-November/029332.html I was thinking of. I have not tried the attached example, though it looks like it should work if you read the rest of that thread.

                            For some reason the thread seems to be split in the archives. Just search for "Generic Highlighter" in November 2010 to find all parts.

                            Nokia Certified Qt Specialist
                            Interested in hearing about Qt related work

                            1 Reply Last reply
                            0
                            • 2 Offline
                              2 Offline
                              2beers
                              wrote on last edited by
                              #14

                              [quote author="ZapB" date="1301577716"]This is the "thread":http://lists.qt.nokia.com/pipermail/qt-interest/2010-November/029332.html I was thinking of. I have not tried the attached example, though it looks like it should work if you read the rest of that thread.

                              For some reason the thread seems to be split in the archives. Just search for "Generic Highlighter" in November 2010 to find all parts.[/quote]

                              Thanks again. I found something. It gave me a few errors. I will try later and see if I can manage to make it work. For those who are interested in the source code can be found in

                              @qt-creator/src/plugins/texteditor/generichighlighter@

                              1 Reply Last reply
                              0
                              • T Offline
                                T Offline
                                tobias.hunger
                                wrote on last edited by
                                #15

                                2beers: You most likely want the QMLJSEditor code (in src/plugins/qmljseditor/), not the generic highlighter one... the first actually parses QML and Javascript while the latter does regexp matching only.

                                1 Reply Last reply
                                0
                                • Z Offline
                                  Z Offline
                                  ZapB
                                  wrote on last edited by
                                  #16

                                  Cool thanks for that Tobias. That will come in handy.

                                  Nokia Certified Qt Specialist
                                  Interested in hearing about Qt related work

                                  1 Reply Last reply
                                  0

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved