Пример #1
0
void bindClass(QScriptEngine &engine, const QString &name) {
  const QMetaObject *metaObj = &T::staticMetaObject;
  QScriptValue ctor          = engine.newFunction(T::ctor);
  QScriptValue proto         = engine.newQMetaObject(metaObj, ctor);
  engine.globalObject().setProperty(name, proto);
  engine.setDefaultPrototype(qMetaTypeId<T *>(), proto);
}
Пример #2
0
int main(int argc, char *argv[])
{
    Q_INIT_RESOURCE(tetrix);

//! [1]
    QApplication app(argc, argv);
    QScriptEngine engine;

    QScriptValue Qt = engine.newQMetaObject(QtMetaObject::get());
    Qt.setProperty("App", engine.newQObject(&app));
    engine.globalObject().setProperty("Qt", Qt);
//! [1]

#ifndef QT_NO_SCRIPTTOOLS
    QScriptEngineDebugger debugger;
    debugger.attachTo(&engine);
    QMainWindow *debugWindow = debugger.standardWindow();
    debugWindow->resize(1024, 640);
#endif

//! [2]
    evaluateFile(engine, ":/tetrixpiece.js");
    evaluateFile(engine, ":/tetrixboard.js");
    evaluateFile(engine, ":/tetrixwindow.js");
//! [2]

//! [3]
    TetrixUiLoader loader;
    QFile uiFile(":/tetrixwindow.ui");
    uiFile.open(QIODevice::ReadOnly);
    QWidget *ui = loader.load(&uiFile);
    uiFile.close();

    QScriptValue ctor = engine.evaluate("TetrixWindow");
    QScriptValue scriptUi = engine.newQObject(ui, QScriptEngine::ScriptOwnership);
    QScriptValue tetrix = ctor.construct(QScriptValueList() << scriptUi);
//! [3]

    QPushButton *debugButton = qFindChild<QPushButton*>(ui, "debugButton");
#ifndef QT_NO_SCRIPTTOOLS
    QObject::connect(debugButton, SIGNAL(clicked()),
                     debugger.action(QScriptEngineDebugger::InterruptAction),
                     SIGNAL(triggered()));
    QObject::connect(debugButton, SIGNAL(clicked()),
                     debugWindow, SLOT(show()));
#else
    debugButton->hide();
#endif

//! [4]
    ui->resize(550, 370);
    ui->show();

    qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
    return app.exec();
//! [4]
}
Пример #3
0
void QTrajPool::Register(QScriptEngine& engine)
{
    QScriptValue ctor = engine.newFunction(QTrajPool::New);
    QScriptValue metaObject = engine.newQMetaObject(&QTrajPool::staticMetaObject, ctor);
    engine.globalObject().setProperty("TrajPool", metaObject);
}
Пример #4
0
void QHistogram::Register(QScriptEngine& engine)
{
    QScriptValue ctor = engine.newFunction(QHistogram::New);
    QScriptValue metaObject = engine.newQMetaObject(&QHistogram::staticMetaObject, ctor);
    engine.globalObject().setProperty("Histogram", metaObject);
}
Пример #5
0
void QVolumeData::Register(QScriptEngine& engine)
{
    QScriptValue ctor = engine.newFunction(QVolumeData::New);
    QScriptValue metaObject = engine.newQMetaObject(&QVolumeData::staticMetaObject, ctor);
    engine.globalObject().setProperty("VolumeData", metaObject);
}