VivoQuant 6.5.0
Loading...
Searching...
No Matches
ScriptConsole Class Reference

Description

Makes what scripts print available to the rest of VivoQuant.

Scripts print with QJSEngine's own console: console.log(), console.debug(), console.info(), console.warn(), console.error(), console.exception() and print() write each call to the Qt log in the js category. The application's message handler (Logging) passes those messages to handleMessage(), which emits them as output() from every ScriptConsole on the thread that printed them. The text is exactly what the log gets: QJSEngine formats it (arrays in brackets, objects as "[object Object]").

Not included: console.time(), console.count() and console.assert(), which Qt logs in the default category like any application message, and VQ.debug(), which goes to the log and the status bar.

Anything that wants to show script output connects to output(), for example the Workflow Assistant while it runs a snippet, or the VivoScript Console. Scripts never nest (see VQ.isRunning()), so a listener that connects for the length of one run sees that run's output, including output printed while the script waits. (It also sees output from script code that runs during the wait for other reasons, such as a timer an earlier script started.)

Nothing is installed in the script engine, so scripts can't break or bypass this, and the log is the same with and without listeners.

Public Types

enum  Level { Log , Info , Warning , Error }

Signals

void output (ScriptConsole::Level level, string text)
 One message a script printed, as it appears in the log.

Static Public Member Functions

static void handleMessage (QtMsgType type, QMessageLogContext &context, string message)
static string format (Object &value)

Static Public Attributes

static constexpr int maxLength = 10000
 Longest text format() returns.

Member Enumeration Documentation

◆ Level

enum Level
Enumerator
Log 

console.log(), console.debug(), print()

Info 

console.info()

Warning 

console.warn()

Error 

console.error(), console.exception()

Member Function Documentation

◆ format()

string format ( Object & value)
static

Text for showing a script result: its string value, shortened to about maxLength characters. Can run script code (an overridden toString()): see VQ.formatResult().

◆ handleMessage()

void handleMessage ( QtMsgType type,
QMessageLogContext & context,
string message )
static

For the application's message handler: emits message as output() from every ScriptConsole on the current thread if it is script output (category js). Never logs anything itself.