Parent Previous Next


Strings and other QtScript objects that Qt Scripting can cast directly can be stored in objects.

All global objects do not automatically persist when the User closes Tw.

If you have difficulties, the safest bet are simple things like numerical values and strings - and don't forget JSON structures.

Once stored (with a name created by the script writer), the global can be tested for (by name - does it exist already? - hasGlobal) and be re-read back into QtScript.

Globals are stored for as long as the Tw editor is still running, and should be retrieved and formatted (possibly json) and saved to disk if required for later use.

There are two types of Globals.

    1. Globals that are available from and to any script while the Tw editor is still open, see Application Wide Globals

    1. And globals that are assigned to a particular script, they are available again during the current Tw session, if the script that created them is used again. Other scripts do not have access to globals stored by another script,  see TW.script.hasGlobal(QString)  TW.script.setGlobal(QString,QVariant)  and TW.script.getGlobal(QString)  



Returns a boolean (true or false ) showing whether the global has already been created and set.

setGlobal(QString)"font_name", yourObject);

TW.script.setGlobal("anyThing_you_like", anotherObject);

The object should be one that Qt can cast (convert) from QtScript see table here:

Default Conversion from Qt Script to C++

If you have difficulties, the safest bet are simple things like numerical values and strings.


var myGlobalVariable ="font_name");

var myScriptVariable = TW.script.getGlobal("anyThing_you_like");

Returns the global named, to script, and stores it in the variable name you supply.

Use hasGlobal first if unsure of its existence.

Unsetting Global variables"foo")




> How do I get rid of a global variable I've set

Oops, I think that was overlooked when the "globals" framework was


I added the two functions"foo") and

TW.script.unsetGlobal("foo") in r994. They should do just what you want.



void TWApp::setGlobal(const QString& key, const QVariant& val)

Created with the Personal Edition of HelpNDoc: Full featured Documentation generator