Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Deleting object

Deleting object

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 3 Posters 1.5k Views
  • 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.
  • V Offline
    V Offline
    VeNToR
    wrote on last edited by
    #1

    Hi;

    How to delete a object that created by new like follows;

    var myObject;
    myObject = new test(); // or String
    delete myObject;

    This example occures exception.

    Thanks.

    JonBJ 1 Reply Last reply
    0
    • V VeNToR

      Hi;

      How to delete a object that created by new like follows;

      var myObject;
      myObject = new test(); // or String
      delete myObject;

      This example occures exception.

      Thanks.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @VeNToR
      I don't use QML, but I feel like throwing my hat into the ring! But assuming this example represents usage of plain JavaScript, you do not use delete against a newed object in the way you would expect in, say, C++.

      The JS delete statement only deletes an object's properties (hence your exception). You cannot delete an object: you have to allow JS to garbage collect them when there are no more references to the object.

      So in your case you can just do nothing and it will get gc-ed on scope exit, or you can just go myObject = null; beforehand if you wish (though it may well not make JS gc it any sooner).

      V 1 Reply Last reply
      2
      • JonBJ JonB

        @VeNToR
        I don't use QML, but I feel like throwing my hat into the ring! But assuming this example represents usage of plain JavaScript, you do not use delete against a newed object in the way you would expect in, say, C++.

        The JS delete statement only deletes an object's properties (hence your exception). You cannot delete an object: you have to allow JS to garbage collect them when there are no more references to the object.

        So in your case you can just do nothing and it will get gc-ed on scope exit, or you can just go myObject = null; beforehand if you wish (though it may well not make JS gc it any sooner).

        V Offline
        V Offline
        VeNToR
        wrote on last edited by
        #3

        @JonB Thank for quick reply. I convert to "test" object to function, and, I have to delete (in my opinion) cause of that it keeps many C++ object inside.

        JonBJ 1 Reply Last reply
        0
        • V VeNToR

          @JonB Thank for quick reply. I convert to "test" object to function, and, I have to delete (in my opinion) cause of that it keeps many C++ object inside.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @VeNToR
          I'm afraid I don't know what you mean. If you are happy, that's fine, if you want to show your new code, I'll look at it.

          Pablo J. RoginaP 1 Reply Last reply
          0
          • JonBJ JonB

            @VeNToR
            I'm afraid I don't know what you mean. If you are happy, that's fine, if you want to show your new code, I'll look at it.

            Pablo J. RoginaP Offline
            Pablo J. RoginaP Offline
            Pablo J. Rogina
            wrote on last edited by
            #5

            @VeNToR as mentioned before, JavaScript delete operator is not directly related to new operator.

            Please refer to documentation for more details, as your issue seems not related to QML (Qt) itself.

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • V Offline
              V Offline
              VeNToR
              wrote on last edited by
              #6

              Thanks all ! I am moving codes from js to c++. At this way an other problem, qml can not handle exception from c++ (QJSEngine::evaluate("throw error;").

              1 Reply Last reply
              0

              • Login

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