×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    54

    Javascript Arrays communicating with QT

    Hi there

    I am making an application that allows Javascript to call QT functions and vice versa and in the simplest case it works fine.

    If the functions being called have 0 params or the param types are just Strings, then this isnt a problem.

    However, I have a situation where there is an array that must be passed from JavaScript to QT.

    I am not sure what type to specify the param in QT. If I try to use QList<QString>, there is a JavaScript error saying unknown type. If however, I change this type to just QString, the values get sent across but comma separated. This is a fine solution for 1 dimensional arrays.

    However, say I have two dimensional arrays, the above solution doesn't work. Does anyone know what type param I should put in my slot that can receive multi dimensional javascript arrays?

    Thx!

  2. #2
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Javascript Arrays communicating with QT

    I would think that the only legitimate way to pass an array from JS to Qt would be as a QList<QVariant>.

  3. #3
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    54

    Re: Javascript Arrays communicating with QT

    Thanks, it worked a treat.

    It's also possible to just use QVariant and then check if its a list within the method. That can make it a more widely used, thanks for the tip!

  4. #4
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Javascript Arrays communicating with QT

    A Javascript/JSON data string is topologically identical to a QVariant that can take any of the forms:
    • Numeric (integer or float)
    • Boolean
    • Null
    • QString
    • QList<QVariant>
    • QMap<QString,QVariant>

    (Where the embedded QVariants recursively refer to the above list)

    It's an easy transformation back and forth between the two.

Similar Threads

  1. Qt for Symbian development resources
    By liuxg in forum [Archived] Qt General ( Qt技术)
    Replies: 55
    Last Post: 2011-01-26, 04:06
  2. automatic rotate screen on meamo
    By fily_love in forum Nokia N9
    Replies: 27
    Last Post: 2010-04-06, 08:37
  3. gsreamer-0.10-plugins-good+Phonon
    By niqt in forum Nokia N9
    Replies: 10
    Last Post: 2010-03-05, 09:56
  4. kinetic scrolling
    By stalep in forum Nokia N9
    Replies: 10
    Last Post: 2009-12-08, 12:41
  5. Senior QT Client Developer (Dublin, Ireland)
    By marynyc in forum News and Announcements
    Replies: 0
    Last Post: 2009-06-02, 18:24

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×