Basic question about arrays in QScript



  • Hi all ,

    I am developing an application where users can call API through scripts

    **```

    example.qs
    
    
        var target_values = new Array();
        target_values.push(0x000);
        target_values.push(0x10000);
        target_values.push(0x4000);
        target_values.push(0x13000);
        target_values.push(0xE000);
        target_values.push(0x10000);
    
         get_Data(target_values);
    
    target_values is the array . so  i tried  to define the get_Data function in cpp as follows 
    
    
    
    

    **```

    example.cpp
    
    void get_Data( const QString values[])
    {
        
        QString values1 = values[0];    //get the first element at index 0
        doDebug("the value  of  first elements is   "+values1.toStdString());   // print the first element on log window
    }
    

    but i am getting error

    TypeError: cannot call get_Data(): argument 1 has unknown type `const QString[]' (register the type with qScriptRegisterMetaType())
     
    ERROR:   Script info: 'logError(msg = TypeError: cannot call get_Data(): argument 1 has unknown type `const QString[]' (register the type with qScriptRegisterMetaType())) at -1'
    
    is there any way to solve this issue . 
    

  • Moderators

    @akshay123 Check http://doc.qt.io/qt-5/qtscript-index.html "Default Conversion from Qt Script to C++" chapter.
    An Array will be QVariantList not a C++ array.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.