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
QtWS25 Last Chance

Basic question about arrays in QScript

Scheduled Pinned Locked Moved Unsolved General and Desktop
qscript
2 Posts 2 Posters 665 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 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 . 
    
    jsulmJ 1 Reply Last reply
    0
    • A akshay123

      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 . 
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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

      • Login

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