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. QT Script - assigned struct in script

QT Script - assigned struct in script

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 276 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.
  • P Offline
    P Offline
    poucz
    wrote on last edited by
    #1

    Hello,

    I'm writing program, that have struct with data (only data). This struct has no Q_OBJECT macro and isn't inherit from QObject.
    Something like this:

    struct DATA2{
         QString beta;
         int b;
    };
    
    struct DATA{
         QString alfa;
         int a;
         DATA2 d;
         ......
    };
    

    Now I want use script to process this struct and return QString:

    
        script_engine=new QScriptEngine();
            
        DATA data;
        QScriptValue arg=script_engine->newQObject(&data);
        script_engine->globalObject().setProperty("arg",arg);
    
        QScriptValue val=script_engine->evaluate(script_content);
        if(val.isError()){
            WARNING<<"ERROR: "<<val.property("lineNumber").toInteger()<<"  - "<<val.toString();
        }else{
            INFO<<val.toString();
        }
    
    

    Is there a way to do this? Without write getter function for all records in the structure? Script will only read values.

    Thank you

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      I dont think so.
      It has to be a QObject and use properties.

      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