本文整理汇总了C++中QScriptEngine::installTranslatorFunctions方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptEngine::installTranslatorFunctions方法的具体用法?C++ QScriptEngine::installTranslatorFunctions怎么用?C++ QScriptEngine::installTranslatorFunctions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptEngine
的用法示例。
在下文中一共展示了QScriptEngine::installTranslatorFunctions方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QScriptEngine
QScriptEngine * PERPScriptEngine::newEngine(QObject *parent, QScriptEngineDebugger *debugger)
{
QScriptEngine *engine = new QScriptEngine(parent);
if ( debugger != NULL ) {
debugger->attachTo(engine);
}
PERPScriptEngine::registerScriptsTypes(engine);
engine->installTranslatorFunctions();
PERPScriptEngine::importExtensions(engine);
return engine;
}
示例2: main
//! [0]
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(helloscript);
//! [0]
//! [1]
QApplication app(argc, argv);
QScriptEngine engine;
QTranslator translator;
translator.load("helloscript_la");
app.installTranslator(&translator);
engine.installTranslatorFunctions();
//! [1]
//! [2]
QPushButton button;
QScriptValue scriptButton = engine.newQObject(&button);
engine.globalObject().setProperty("button", scriptButton);
//! [2]
//! [3]
QString fileName(":/helloscript.js");
QFile scriptFile(fileName);
scriptFile.open(QIODevice::ReadOnly);
QTextStream stream(&scriptFile);
QString contents = stream.readAll();
scriptFile.close();
//! [3]
#ifdef Q_OS_SYMBIAN
contents.replace("button.show()", "button.showMaximized()");
#endif
//! [4]
QScriptValue result = engine.evaluate(contents, fileName);
//! [4]
//! [5]
if (result.isError()) {
QMessageBox::critical(0, "Hello Script",
QString::fromLatin1("%0:%1: %2")
.arg(fileName)
.arg(result.property("lineNumber").toInt32())
.arg(result.toString()));
return -1;
}
//! [5]
//! [6]
return app.exec();
}
示例3: main
int main(int argc, char **argv)
{
QApplication *app = new QApplication(argc, argv);
app->setApplicationName("kross");
app->setApplicationVersion("0.1");
app->setOrganizationDomain("dipe.org");
QScriptEngine *engine = new QScriptEngine();
engine->installTranslatorFunctions();
/*K4AboutData about("kross",0,ki18n("Kross"),"0.1",
ki18n("KDE application to run Kross scripts."),
K4AboutData::License_LGPL,
ki18n("(C) 2006 Sebastian Sauer"),
ki18n("Run Kross scripts."),
"http://kross.dipe.org","[email protected]");*/
//about.addAuthor(ki18n("Sebastian Sauer"), ki18n("Author"), "[email protected]");
// Initialize command line args
// Tell which options are supported and parse them.
QCommandLineParser parser;
parser.setApplicationDescription(QCoreApplication::translate("main", "KDE application to run Kross scripts."));
parser.addHelpOption();
parser.addOption(QCommandLineOption(QStringList() << "+file", QCoreApplication::translate("main", "Scriptfile")));
parser.process(*app);
const QStringList args = parser.positionalArguments();
// If no options are defined.
if (args.count() < 1) {
parser.showHelp();
//std::cout << "Syntax: " << "kross" << " scriptfile1 [scriptfile2] [scriptfile3] ..." << std::endl;
return -1;
}
QScriptValue global = engine->globalObject();
//qDebug()<<"QLibraryInfo::PluginsPath="<<QLibraryInfo::location(QLibraryInfo::PluginsPath);
engine->importExtension("kross").toString();
foreach (const QString &file, args) {
runScriptFile(engine, file);
}