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. Const string& in QScript (Qt 4.6)

Const string& in QScript (Qt 4.6)

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.6k 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.
  • S Offline
    S Offline
    StevenEBarbaro
    wrote on last edited by
    #1

    Hello everyone,

    I've been using QScriptable to enable a c++ class to be used in QScript.

    I've also been registering some of the return types of the (newly set as) public slots for the above mentioned class to be available in QScript as well

    I can’t seem to figure out a way to register a (const string&) to be a recognized type for use in the script nor have I found a solution online.

    This is an example of how I hooked up std::string successfully

    @
    //Register string with the meta system
    Q_DECLARE_METATYPE(string);
    @

    …

    @
    qRegisterMetaType<string>("string");
    @

    …

    @
    //Identify to the script engine what conversion functions to use for type string
    qScriptRegisterMetaType<string>(&this->engine, & MyScriptHandlingClass::stdStringToScriptValue, & MyScriptHandlingClass::stdStringFromScriptValue);

    QScriptValue string_ctor = this->engine.newFunction(&MyScriptHandlingClass::createStdString);

    //Identify to the script engine what function is to be used to create new strings in the script
    this->engine.globalObject().setProperty(“string”, string_ctor);
    @

    Does anyone have any solutions and/or advice that would help me resolve this issue?

    Thank you very much in advance,

    -Steve

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      If I remember correctly, you have to include the namespace in the metatype declaration:

      @Q_DECLARE_METATYPE(std::string)@

      But why not use QString and QString::toStdString() when needed?

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      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