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. Date with Qt script
Forum Updated to NodeBB v4.3 + New Features

Date with Qt script

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 910 Views
  • 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
    Snyfir
    wrote on last edited by
    #1

    Hello

    With Qt script i would like to test the day number.
    This is my code:

    QScriptValue script = myEngine.newDate(QDateTime::currentDateTime());
    myEngine.globalObject().setProperty("date", script);
    
    myEngine.evaluate("date.day() == 5").toBool();
    

    but it doesn't work.
    I don't know why.
    Thank you for your help.

    JonBJ 1 Reply Last reply
    0
    • S Snyfir

      Hello

      With Qt script i would like to test the day number.
      This is my code:

      QScriptValue script = myEngine.newDate(QDateTime::currentDateTime());
      myEngine.globalObject().setProperty("date", script);
      
      myEngine.evaluate("date.day() == 5").toBool();
      

      but it doesn't work.
      I don't know why.
      Thank you for your help.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Snyfir
      In http://doc.qt.io/qt-5/qscriptvalue.html#details I see:

      QScriptValue supports the types defined in the ECMA-262 standard: The primitive types, which are Undefined, Null, Boolean, Number, and String; and the Object type. Additionally, Qt Script has built-in support for QVariant, QObject and QMetaObject.

      For the object-based types (including Date and RegExp), use the newT() functions in QScriptEngine (e.g. QScriptEngine::newObject()) to create a QScriptValue of the desired type. For the primitive types, use one of the QScriptValue constructor overloads.

      So to me that implies you need to respect the second paragraph for your object to be treated as a Date?

      S 1 Reply Last reply
      0
      • JonBJ JonB

        @Snyfir
        In http://doc.qt.io/qt-5/qscriptvalue.html#details I see:

        QScriptValue supports the types defined in the ECMA-262 standard: The primitive types, which are Undefined, Null, Boolean, Number, and String; and the Object type. Additionally, Qt Script has built-in support for QVariant, QObject and QMetaObject.

        For the object-based types (including Date and RegExp), use the newT() functions in QScriptEngine (e.g. QScriptEngine::newObject()) to create a QScriptValue of the desired type. For the primitive types, use one of the QScriptValue constructor overloads.

        So to me that implies you need to respect the second paragraph for your object to be treated as a Date?

        S Offline
        S Offline
        Snyfir
        wrote on last edited by
        #3

        @JNBarchan
        What do you mean treated as a Date ? do you have an example ?

        JonBJ 1 Reply Last reply
        0
        • S Snyfir

          @JNBarchan
          What do you mean treated as a Date ? do you have an example ?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Snyfir
          I have no example as I've never even used Qt Script! But your QScriptValue script = myEngine.newDate(QDateTime::currentDateTime()); is assigning a value of type Date, which you will later want to perform date-type operation on (date.day()). And it seems to me the manual is saying you need to do some kind of QScriptEngine::newObject()) for Dates.

          Oh, I'm so sorry, is that what your myEngine.newDate() is already doing? My apologies if it is.

          I would at least suggest you evaluate date.day() alone first to see what it is returning, without the == 5 test...

          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