How to use Qt Gui Script in dialog box (example source calculator)



  • i want to use script gui.
    when click any special button, load special ui and connect script file.
    dynamically i want change ui, and script.

    in example source( calculater. path : qt path/examples/script/calculator)
    in main.cpp (no use dialog) it works well.
    but does not works well slot function in dialog box.

    the code is below....

    @
    QScriptEngine engine;

    QString scriptFileName(":/calculator.js");
    QFile scriptFile(scriptFileName);
    scriptFile.open(QIODevice::ReadOnly);
    engine.evaluate(scriptFile.readAll(), scriptFileName);

    QUiLoader loader;
    QFile uiFile(":/calculator.ui");
    uiFile.open(QIODevice::ReadOnly);
    QWidget *ui = loader.load(&uiFile);
    uiFile.close();

    QScriptValue ctor = engine.evaluate("Calculator");
    QScriptValue scriptUi = engine.newQObject(ui, QScriptEngine::ScriptOwnership);
    QScriptValue calc = ctor.construct(QScriptValueList() << scriptUi);
    @

    It does not showed calculator window in dialog box.
    If delete "QScriptValue scriptUi = engine.newQObject(ui, QScriptEngine::ScriptOwnership);" line,
    It shows calculator window, but does not work with script file.

    How can use QT Gui Script in dialog box ..

    please help me...
    thanks.~~


  • Moderators

    welcome to devnet

    Please use "code wrappings":http://qt-project.org/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01 for your posted code sections. This time I have introduced them for you.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.