QtScriptGenerator from Qt Labs is a great way of getting scripting functionality into your apps. However, one has to remember some simple rules – it’s Javascript. As such, you’d be forgiven for writing this:
var flibble = "Hello World";
var my_file = new QFile("hello.txt");
my_file.write(flibble);
my_file.close();
That, won’t work. In fact, it’ll bomb out at line 3 of that script and not close the file. So, obviously really, QFile::write() doesn’t actually support sending strings so, we need to convert it first:
var flibble = "Hello World";
var ba = QByteArray(flibble);
var my_file = new QFile("hello.txt");
my_file.write(ba);
my_file.close();
Job done. It seems really obvious when you think about it – but… heh I imagine someone might Google this at some point.


For what its worth, I found this problem and fixed it by editing the typesystem_core.xml QIODevice class with:
modify-function signature=”write(const char *)”>