Results 1 to 3 of 3

Thread: Returning QVector<qreal> from C++ to QML and back to C++ as QVariantList

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2017
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Returning QVector<qreal> from C++ to QML and back to C++ as QVariantList

    Thanks for the suggestion, you are correct that if the setValues function takes a QVector<qreal>, there is no problem. However in my case the setValues function (which is actually in another class than the getValues function in the real application) needs to be able to take generic arrays, not just qreals. Changing the signature to setValues(const QVariant& variant) solved the problem, I can convert to a QVariantList using variant.value<QVariantList>() (not variant.toList(), which gives an empty list again.) But really, should there not be an error of some kind if I call a function with the wrong argument type?


    (Edited after I realized I had a Q_PROPERTY(QVariantList values WRITE setValues ...) which would "convert" the array into an empty list even though I used a QVariant argument in setValues...)
    Last edited by HÃ¥kon Enger; 17th March 2017 at 09:57.

Similar Threads

  1. Replies: 5
    Last Post: 10th October 2011, 14:26
  2. Replies: 5
    Last Post: 2nd September 2011, 23:11
  3. Replies: 0
    Last Post: 10th January 2011, 09:42
  4. How to log returning control back to the main event loop?
    By piotr.dobrogost in forum Qt Programming
    Replies: 5
    Last Post: 28th September 2009, 09:57
  5. Replies: 12
    Last Post: 14th June 2006, 09:24

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
  •  
Qt is a trademark of The Qt Company.