Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] script not re-evaluating
Forum Updated to NodeBB v4.3 + New Features

[solved] script not re-evaluating

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 895 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    techfort
    wrote on last edited by
    #1

    Hi,

    I have a quite large qt app and want to avoid re-compiling every time i want to change a configuration parameter.
    I thought of adopting a javascript configuration file to be loaded at runtime (using QScriptEngine), everything works perfectly, except if i change the content of the javascript file and re-run the app (without recompiling) the contents of the javascript file are still what they were in the previous run.
    The only way i have to refresh the contents is to do a clean all / run, which defeats the purpose (because i'm back to square 1 at recompiling).

    I tried pushing and popping contexts in QScriptEngine to no avail, and I tried googling as much as possible about scripts not reloading but it seems like there's very little and not entirely relevant.
    I'd be extremely grateful if anybody can help out.
    This is what I'm doing:
    @
    QScriptEngine engine;
    QString configFilename(":/config.qs");
    QFile configScript(configFilename);
    configScript.open(QIODevice::ReadOnly);
    QTextStream stream(&configScript);
    QString contents(stream.readAll());
    configScript.close();

    Config appConfig;
    appConfig.debug = false;
    appConfig.appname = "test";
    QScriptValue cnf = engine.newQObject(&appConfig);
    
    QScriptContext * ctx = engine.pushContext();
    ctx->activationObject().setProperty("config", cnf);
    engine.evaluate(contents, configFilename);
    
    qDebug() << "cnf: " << cnf.property("debug").toBoolean() << ", appname: " << cnf.property("appname").toString();
    engine.popContext();@
    
    1 Reply Last reply
    0
    • T Offline
      T Offline
      techfort
      wrote on last edited by
      #2

      For the record, I resolved the problem.
      The problem was that the config file was loaded as a resource (using the ":" accessor). Obviously this causes qt to "bake" the resource and not reload its contents, which makes sense.
      Using an absolute path resolved the problem.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        Glad you found out and thanks for sharing your findings.

        Can you also please update the thread title prepending [solved] so other forum users may know a solution has been found :)

        Happy coding !

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved