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. Documentation on isDetached?
Forum Updated to NodeBB v4.3 + New Features

Documentation on isDetached?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 754 Views 1 Watching
  • 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    I can see in Qt Creator that the context help shows isDetached on a QVariant type, I cannot find any documentation on this function, I just want to confirm if it means what I think.

    I'm using Qt 4.8 on this project. Does isDetached mean that if true the QVariant isn't set-up ?

    I'm calling property(cpszArray) and I know this property doesn't exist so the QVariant returned does return true when isDetached is called.

    [Edit] In my test code:

    clsArray& clsJSON::operator[](const char* cpszArray) {
        QVariant varArray(property(cpszArray));
        bool blnIsDetached(varArray.isDetached());
        clsArray objArray;
        if ( blnIsDetached == true ) {
            setProperty(cpszArray, objArray.toList());
            varArray = proprty(cpszArray);
            blnIsDetached = varArray.isDetached();
        }
        return objArray;
    }
    

    The above code is very much a work in progress and I know there are issues, the main reason for posting it is to highlight what I'm seeing, when property is called the variant varArray.isDetached() returns true, I was assuming because the property didn't exist, then after calling setProperty I test it again, but it still returns true. The function toList:

    tVarList toList() { return mvlstElements; }
    

    tVarList:

    typedef QList<QVariant> tVarList;
    

    [Edit 2], still no idea what isDetached means, but I've modified the function and now it makes sense:

    clsArray& clsJSON::operator[](const char* cpszArray) {
        QVariant varArray(property(cpszArray));
        bool blnIsValid(varArray.isValid());
        clsArray objArray;
        if ( blnIsValid != true ) {
            setProperty(cpszArray, objArray.toList());
            varArray = proprty(cpszArray);
            blnIsValid = varArray.isValid();
        }
        return objArray;
    }
    

    On the initial call isValid returns false, after calling setProperty then second call to isValid returns true.

    Kind Regards,
    Sy

    KroMignonK 1 Reply Last reply
    0
    • SPlattenS SPlatten

      I can see in Qt Creator that the context help shows isDetached on a QVariant type, I cannot find any documentation on this function, I just want to confirm if it means what I think.

      I'm using Qt 4.8 on this project. Does isDetached mean that if true the QVariant isn't set-up ?

      I'm calling property(cpszArray) and I know this property doesn't exist so the QVariant returned does return true when isDetached is called.

      [Edit] In my test code:

      clsArray& clsJSON::operator[](const char* cpszArray) {
          QVariant varArray(property(cpszArray));
          bool blnIsDetached(varArray.isDetached());
          clsArray objArray;
          if ( blnIsDetached == true ) {
              setProperty(cpszArray, objArray.toList());
              varArray = proprty(cpszArray);
              blnIsDetached = varArray.isDetached();
          }
          return objArray;
      }
      

      The above code is very much a work in progress and I know there are issues, the main reason for posting it is to highlight what I'm seeing, when property is called the variant varArray.isDetached() returns true, I was assuming because the property didn't exist, then after calling setProperty I test it again, but it still returns true. The function toList:

      tVarList toList() { return mvlstElements; }
      

      tVarList:

      typedef QList<QVariant> tVarList;
      

      [Edit 2], still no idea what isDetached means, but I've modified the function and now it makes sense:

      clsArray& clsJSON::operator[](const char* cpszArray) {
          QVariant varArray(property(cpszArray));
          bool blnIsValid(varArray.isValid());
          clsArray objArray;
          if ( blnIsValid != true ) {
              setProperty(cpszArray, objArray.toList());
              varArray = proprty(cpszArray);
              blnIsValid = varArray.isValid();
          }
          return objArray;
      }
      

      On the initial call isValid returns false, after calling setProperty then second call to isValid returns true.

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by KroMignon
      #2

      @SPlatten said in Documentation on isDetached?:

      still no idea what isDetached means, but I've modified the function and now it makes sense:

      I may be wrong, but AFAIK, Qt classes are designed to avoid data copies and isDetached() is to be aware if this class instance (for example QString) holds its own data copy or points to data of another instance.
      You can force detaching by called detach()

      EDIT: for more details take a look at https://doc.qt.io/qt-5/implicit-sharing.html

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      1 Reply Last reply
      4
      • kkoehneK Offline
        kkoehneK Offline
        kkoehne
        Moderators
        wrote on last edited by
        #3

        @KroMignon said in Documentation on isDetached?:

        I may be wrong, but AFAIK, Qt classes are designed to avoid data copies and isDetached() is to be aware if this class instance (for example QString) holds its own data copy or points to data of another instance.

        Jus to confirm that this is the case. If you look up isDetached() in qvariant.h for Qt 4.8, it's defined as

        inline bool QVariant::isDetached() const
        { return !d.is_shared || d.data.shared->ref == 1; }
        

        Director R&D, The Qt Company

        1 Reply Last reply
        3

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved