GO2cam Javascript API
GO2SUtil Class Reference

Class of utility functions. More...

Inherits QObject.

Static Public Member Functions

static Number ExecuteProgram (String filename, Array< String > arg=Array< String >())
 
static Number ExecuteProgram (String filename, String arg)
 
static QJSValue fetch (String url, Number timeout=30000)
 
static QJSValue fetch (String url, QJSValue options, Number timeout=30000)
 
static QJSValue fetchMultipart (String url, QJSValue formData, Number timeout=30000)
 
static String GenerateName (String name="", String prefix="", String suffix="")
 
static void ImportJS (String dir, String name)
 
static void ImportJS (String name)
 

Detailed Description

Class of utility functions.

Member Function Documentation

◆ ExecuteProgram() [1/2]

static Number GO2SUtil::ExecuteProgram ( String filename,
Array< String > arg = Array< String >() )
static

Execute an external program, and waits the program exits

GO2SUtil.ExecuteProgram('program1.exe');
GO2SUtil.ExecuteProgram('program2.exe', [arg1, arg2]);
Class of utility functions.
Definition GO2SUtil.hpp:13
static Number ExecuteProgram(String filename, Array< String > arg=Array< String >())
Returns
the exit code of the program
Parameters
[in]filenamepath of the executable
[in]argoptional arguments for the executable

◆ ExecuteProgram() [2/2]

static Number GO2SUtil::ExecuteProgram ( String filename,
String arg )
static

Execute an external program with arguments formatted in a single string

GO2SUtil.ExecuteProgram('program.exe', 'arg1, arg2');
Returns
the exit code of the program
Version
6.12
Parameters
[in]filenamepath of the executable
[in]argstring of arguments

◆ fetch() [1/2]

static QJSValue GO2SUtil::fetch ( String url,
Number timeout = 30000 )
static

Perform HTTP fetch request (simple GET)

var response = GO2SUtil.fetch('https://api.example.com/data');
if (response.ok) {
var jsonData = JSON.parse(response.body);
}
static QJSValue fetch(String url, Number timeout=30000)
Returns
a Response object with ok, status, statusText, url, headers, and body properties
Version
2026
Parameters
[in]urlURL to fetch
[in]timeouttime out in milliseconds

◆ fetch() [2/2]

static QJSValue GO2SUtil::fetch ( String url,
QJSValue options,
Number timeout = 30000 )
static

Perform HTTP fetch request with options (similar to JavaScript fetch)

var options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({key: 'value'})
};
var response = GO2SUtil.fetch('https://api.example.com/data', options);
if (response.ok) {
var result = JSON.parse(response.body);
}
Returns
a Response object with ok, status, statusText, url, headers, and body properties
Version
2026
Parameters
[in]urlURL to fetch
[in]optionsOptions object with method, headers, body
[in]timeouttime out in milliseconds

◆ fetchMultipart()

static QJSValue GO2SUtil::fetchMultipart ( String url,
QJSValue formData,
Number timeout = 30000 )
static

Perform HTTP multipart/form-data request with files and JSON data

var formData = {
method: 'POST',
headers: {'Authorization': 'Bearer token123'},
data: JSON.stringify({pieceId: '12345'}),
files: [
{fieldName: 'files', filename: 'part1.stl', path: '/temp/part1.stl'},
{fieldName: 'files', filename: 'part2.stl', path: '/temp/part2.stl'}
]
};
var response = GO2SUtil.fetchMultipart('https://api.example.com/upload', formData);
if (response.ok) {
var result = JSON.parse(response.body);
}
static QJSValue fetchMultipart(String url, QJSValue formData, Number timeout=30000)
Returns
a Response object with ok, status, statusText, url, headers, and body properties
Version
2026
Parameters
[in]urlURL to post to
[in]formDataFormData object with data and files arrays
[in]timeouttime out in milliseconds

◆ GenerateName()

static String GO2SUtil::GenerateName ( String name = "",
String prefix = "",
String suffix = "" )
static

Generate a name not already existing in database

var name = GO2SUtil.GenerateName("GO2cam", "robot");
static String GenerateName(String name="", String prefix="", String suffix="")

Output: GO2cam_robot, if already exist in Bdd -> GO2cam_robot_1

Returns
a String name.
Parameters
[in]name
[in]prefix
[in]suffix

◆ ImportJS() [1/2]

static void GO2SUtil::ImportJS ( String dir,
String name )
static

Import another script and execute it

Warning
if 2 variables or functions have the same name, the last one is kept
Parameters
[in]dirpath of the include file
[in]namefile name of the include file

◆ ImportJS() [2/2]

static void GO2SUtil::ImportJS ( String name)
static

Import another script and execute it

Warning
if 2 variables or functions have the same name, the last one is kept
Parameters
[in]namefullName of the include file