Results 1 to 3 of 3

Thread: return a QVariantList

  1. #1
    Join Date
    Feb 2013
    Posts
    50
    Thanks
    5

    Default return a QVariantList

    Hi,

    it is not ok to return a QVariantList variable from a function right?

    e.g.,

    Qt Code:
    1. QVariantList app::f()
    2. {
    3. QVariantList obj;
    4. return obj;
    5. }
    To copy to clipboard, switch view to plain text mode 
    because obj will go out of scope when f exits?? (ps.I understand this maybe common to all data types, just checking).

  2. #2
    Join Date
    Dec 2012
    Posts
    90
    Thanks
    5
    Thanked 20 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: return a QVariantList

    No, it's OK, because here obj is being returned by value(i.e. a copy of obj will be created and then returned).

    You shouldn't do this only if value is returned by reference, for example:
    Qt Code:
    1. QVariantList &app::f ()
    2. {
    3. QVariantList obj;
    4. ///WRONG!
    5. return obj;
    6. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2013
    Posts
    50
    Thanks
    5

    Default Re: return a QVariantList

    Yes I also think it is ok in general to return QList QMap or any other data type.

    I think problematic also next to what you mentioned is if I am supposed to return a pointer from a function and I return
    a pointer to a local variable (e.g., int x) that was defined inside the function.

Similar Threads

  1. Replies: 1
    Last Post: 2nd January 2013, 09:48
  2. Convert a QByteArray to a QVariantList
    By franco.amato in forum Newbie
    Replies: 21
    Last Post: 13th May 2010, 00:17
  3. QSqlite store/retrieve QVariantList
    By gonzoboy! in forum Qt Programming
    Replies: 4
    Last Post: 5th December 2009, 18:26
  4. QVariantList from QScript?
    By musla in forum Qt Programming
    Replies: 0
    Last Post: 29th June 2009, 10:22
  5. QVariantList HELP!!!
    By magikalpnoi in forum Qt Programming
    Replies: 1
    Last Post: 12th September 2006, 09:13

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.