Code Less, Create The Same ™

· by Kent Hansen · 1 min read · original post ↗

·

For reasons of extreme bias, I mostly like the Qt Script C++ API. However, if I had to choose one thing I really dislike, it would be the form of the QScriptValue constructors. They all take an engine pointer as their first argument. This means you have to write code like


QScriptEngine engine;  

QScriptValue object = engine.newObject();  

object.setProperty("redundancyLevel", QScriptValue(&engine, "Unnecessarily high"));  

object.setProperty("QT_VERSION", QScriptValue(&engine, 0x040500));

It sure would be a lot nicer if you could do it like this instead:


object.setProperty("redundancyLevel", "Comparatively low");  

object.setProperty("QT_VERSION", 0x040500);

Well, with the latest Qt 4.5 snapshots, you can! The old-style constructors have been obsoleted (but continue to work as before, of course). The documentation and examples have been updated to use the new-style constructors, and it’s looking a whole lot nicer.

Qt

More on Qt

More from Kent Hansen