Results 1 to 6 of 6

Thread: ActiveQt : Setting Currency properties of a QAxObject

  1. #1
    Join Date
    Jul 2012
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default ActiveQt : Setting Currency properties of a QAxObject

    I'm accessing some third-party COM objects that have Currency/Decimal properties. ActiveQt supports the Currency (CY) type of COM, which is simply an int64, using qlonglong. For instance, an amount of $1.23 is saved as 12300. Reading such a currency property in a QAxObject is not a problem -- I simply divide by 10000 to get the real amount. However, setting such a property is a problem since the input is taken "at face value". Floating point numbers are converted to qlonglongs and cents are omitted in the conversion:
    Qt Code:
    1. double value1 = 1.23;
    2. qaxobject->setProperty("Amount", value1);
    3. // property("Amount") returns 10000 = $1
    4.  
    5. // Multiplying by 10,000 beforehand therefore doesn't work either
    6. qlonglong value2 = 12300; // trying again for $1.23
    7. qaxobject->setProperty("Amount", value2);
    8. // property("Amount") returns 123000000 = $12300
    To copy to clipboard, switch view to plain text mode 
    Is this because of the conversion to QVariant? If so, does anybody know a way around setProperty/dynamicCall to set the property in its native type? Or are the third-party components at fault? Thanks a lot.
    (Using Qt4.8.2, Visual Studio 2010)

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: ActiveQt : Setting Currency properties of a QAxObject

    Try:
    Qt Code:
    1. qlonglong value2 = 12300;
    2. qaxobject->setProperty("Amount", QVariant(value2));
    To copy to clipboard, switch view to plain text mode 
    I suspect you are getting a QVariant(int) (because the value will fit) instead of QVariant(qlonglong) inside the ActiveQt marhsalling code which then fails to match it to the CY field properly.

  3. #3
    Join Date
    Jul 2012
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ActiveQt : Setting Currency properties of a QAxObject

    I tried that. Unfortunately, it still returns 123000000.

  4. #4
    Join Date
    Jul 2012
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ActiveQt : Setting Currency properties of a QAxObject

    Digging a bit deeper, I found the following in Qt's qaxtypes.cpp, in the method QVariantToVARIANT(..., bool out = false). QVariantToVARIANT is used by QAxBase in its method internalProperty to convert QVariants to the Microsoft VARIANT format when setting properties.
    Qt Code:
    1. case QVariant::LongLong:
    2. // arg.vt is set by QAxBase to VT_ERROR and out == false, so the first two if-cases are skipped
    3. if (out && arg.vt == (VT_CY|VT_BYREF)) {
    4. arg.pcyVal->int64 = qvar.toLongLong();
    5. // this checks for VisualStudio 2005 or higher
    6. #if !defined(Q_OS_WINCE) && defined(_MSC_VER) && _MSC_VER >= 1400
    7. } else if (out && arg.vt == (VT_I8|VT_BYREF)) {
    8. *arg.pllVal = qvar.toLongLong();
    9. } else {
    10. arg.vt = VT_I8; // method jumps here because I use VisualStudio 2010 on Win7Pro
    11. arg.llVal = qvar.toLongLong(); // here it sets an integer value, not a currency value
    12. if (out) {
    13. arg.pllVal = new LONGLONG(arg.llVal);
    14. arg.vt |= VT_BYREF;
    15. }
    16. }
    17. #else
    18. } else {
    19. arg.vt = VT_CY; // if it jumped here everything would be fine.
    20. arg.cyVal.int64 = qvar.toLongLong();
    21. if (out) {
    22. arg.pcyVal = new CY(arg.cyVal);
    23. arg.vt |= VT_BYREF;
    24. }
    25. }
    26. #endif
    27. break;
    To copy to clipboard, switch view to plain text mode 
    Why does it check for _MSC_VER >= 1400 (Visual Studio 2005)? If I used something older or no VisualStudio at all, then there wouldn't be a problem. This basically removes support for the Currency type from VisualStudio/Qt.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: ActiveQt : Setting Currency properties of a QAxObject

    This might seem familiar: https://bugreports.qt-project.org/browse/QTBUG-3828

    Why do you think arg.vt == VT_ERROR? That seems an odd thing.

  6. The following user says thank you to ChrisW67 for this useful post:

    drfitz (27th July 2012)

  7. #6
    Join Date
    Jul 2012
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ActiveQt : Setting Currency properties of a QAxObject

    Thanks for the link. We were about to write a Qt bug report. Good to know it's been hanging around there since 2009. Well, we'll probably have write our own fix if they don't.
    Quote Originally Posted by ChrisW67 View Post
    Why do you think arg.vt == VT_ERROR? That seems an odd thing.
    It's just an initial value. This is what QAxBase does when it calls the method:
    Qt Code:
    1. int QAxBase::internalProperty(QMetaObject::Call call, int index, void **v)
    2. {
    3. ....
    4. case QMetaObject::WriteProperty:
    5. {
    6. .....
    7. arg.vt = VT_ERROR;
    8. .....
    9. QVariantToVARIANT(qvar, arg, proptype);
    10. if (arg.vt == VT_EMPTY || arg.vt == VT_ERROR) {
    11. qWarning("QAxBase::setProperty: Unhandled property type %s", prop.typeName());
    12. break;
    13. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Currency symbol for current locale
    By Jeffb in forum Qt Programming
    Replies: 2
    Last Post: 2nd February 2012, 13:11
  2. ActiveQT (QAxObject) questions
    By semajnosnibor in forum Qt Programming
    Replies: 3
    Last Post: 19th January 2012, 17:15
  3. Replies: 3
    Last Post: 25th September 2011, 14:44
  4. Currency Symbol/Sign with QLocale
    By NoRulez in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2010, 23:52
  5. MySQL currency storage problem
    By MarkoSan in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2008, 09:04

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.