Results 1 to 5 of 5

Thread: a question about QVariant

  1. #1
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default a question about QVariant

    Hi all
    In the source code of Qt, we could see the below code

    Qt Code:
    1. return QVariant();
    To copy to clipboard, switch view to plain text mode 
    VS9 will report a warning:
    warning C4172: returning address of local variable or temporary
    We all know returning address of local var is very dangerous!
    I want to know is that(return QVariant() correct?
    Jerry

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: a question about QVariant

    This is returning a name less empty object. So no probs !!

  3. #3
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: a question about QVariant

    Depends on the Signature.

    Qt Code:
    1. // bad, return by reference a local variable
    2. QVariant& myClass::myFunction() {
    3. return QVariant();
    4. }
    5.  
    6. // ok, return by copy
    7. QVariant myClass::myFunction() {
    8. return QVariant();
    9. }
    10.  
    11. // Also ok, return by reference
    12. QVariant& myClass::myFunction(QVariant& my_variant) {
    13. return my_variant;
    14. }
    To copy to clipboard, switch view to plain text mode 

    See (for example) here for a detailed expanation

  4. The following user says thank you to nightghost for this useful post:

    calmspeaker (14th August 2009)

  5. #4
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a question about QVariant

    Quote Originally Posted by yogeshgokul View Post
    This is returning a name less empty object. So no probs !!
    Thank you for replying!
    What do you mean by empty object?
    In Qt doc:
    QVariant::QVariant ()

    Constructs an invalid variant.
    In Qt source code:
    Qt Code:
    1. struct Private
    2. {
    3. inline Private(): type(Invalid), is_shared(false), is_null(true) { data.ptr = 0; }
    4. inline Private(const Private &other)
    5. : data(other.data), type(other.type),
    6. is_shared(other.is_shared), is_null(other.is_null)
    7. {}
    8. union Data
    9. {
    10. char c;
    11. int i;
    12. uint u;
    13. bool b;
    14. double d;
    15. qlonglong ll;
    16. qulonglong ull;
    17. void *ptr;
    18. PrivateShared *shared;
    19. } data;
    20. uint type : 30;
    21. uint is_shared : 1;
    22. uint is_null : 1;
    23. };
    To copy to clipboard, switch view to plain text mode 
    I deduce that the QVariant() is not empty.It at least contains type of which value is Invalid!
    Jerry

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: a question about QVariant

    Empty in the terms of semantics ("without any user relevant data").
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Convert between a custom data type wrapped in a QVariant
    By darkadept in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2009, 10:07
  2. QVariant question
    By yunpeng880 in forum Qt Programming
    Replies: 2
    Last Post: 5th March 2009, 01:43
  3. Getting Microsoft Word Object to SaveAs
    By jvwebb in forum Newbie
    Replies: 3
    Last Post: 2nd September 2008, 20:27
  4. QVariant custom/user type comparison
    By gri in forum Qt Programming
    Replies: 2
    Last Post: 12th August 2008, 15:36
  5. Crash caused by QVariant (mis)use
    By mclark in forum Newbie
    Replies: 2
    Last Post: 31st October 2006, 16:05

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.