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. Basic question about arrays in QScript
Forum Updated to NodeBB v4.3 + New Features

Basic question about arrays in QScript

Scheduled Pinned Locked Moved Unsolved General and Desktop
qscript
2 Posts 2 Posters 672 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.
  • A Offline
    A Offline
    akshay123
    wrote on 20 Mar 2017, 08:03 last edited by A Former User
    #1

    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 . 
    
    J 1 Reply Last reply 20 Mar 2017, 08:08
    0
    • A akshay123
      20 Mar 2017, 08:03

      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 . 
      
      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 20 Mar 2017, 08:08 last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      2/2

      20 Mar 2017, 08:08

      • Login

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