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. QDeleteAll issue with QMap<QString,QObject *>
Forum Updated to NodeBB v4.3 + New Features

QDeleteAll issue with QMap<QString,QObject *>

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 4 Posters 1.3k Views 4 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.
  • B Offline
    B Offline
    Babs
    wrote on last edited by
    #1

    Hello, I'm working on a QML API.
    I call QDeleteAll in order to delete my list of Objects stored in QMap<QString, CanMessage*>. CanMessage inherits QObject.
    when i call the qDeleteAll my application crash.
    Can anyone help,pls?

    JKSHJ 1 Reply Last reply
    0
    • B Babs

      Hello, I'm working on a QML API.
      I call QDeleteAll in order to delete my list of Objects stored in QMap<QString, CanMessage*>. CanMessage inherits QObject.
      when i call the qDeleteAll my application crash.
      Can anyone help,pls?

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @Babs said in QDeleteAll issue with QMap<QString,QObject *>:

      when i call the qDeleteAll my application crash.

      Run your Debugger. What does your Stack Trace show when it crashes?

      You might need to call QObject::deleteLater() instead of deleting them directly.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      B 1 Reply Last reply
      2
      • JKSHJ JKSH

        @Babs said in QDeleteAll issue with QMap<QString,QObject *>:

        when i call the qDeleteAll my application crash.

        Run your Debugger. What does your Stack Trace show when it crashes?

        You might need to call QObject::deleteLater() instead of deleting them directly.

        B Offline
        B Offline
        Babs
        wrote on last edited by
        #3

        @JKSH deleteLater() is not working either. It provoke a segmentation fault

        1 Reply Last reply
        0
        • KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by KroMignon
          #4

          @Babs said in QDeleteAll issue with QMap<QString,QObject *>:

          when i call the qDeleteAll my application crash.

          Are you sure your QMap is correctly initialized? All values are valid? No dangling pointers?

          As you are saying CanMessage inherits from QObject, I would suggest you to use QPointer and change your type declaration to QMap<QString , QPointer<CanMessage> >, this should avoid to have duplicated deallocation.

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

          B 1 Reply Last reply
          3
          • KroMignonK KroMignon

            @Babs said in QDeleteAll issue with QMap<QString,QObject *>:

            when i call the qDeleteAll my application crash.

            Are you sure your QMap is correctly initialized? All values are valid? No dangling pointers?

            As you are saying CanMessage inherits from QObject, I would suggest you to use QPointer and change your type declaration to QMap<QString , QPointer<CanMessage> >, this should avoid to have duplicated deallocation.

            B Offline
            B Offline
            Babs
            wrote on last edited by
            #5

            @KroMignon thank you. I used QPointer and it works properly.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Then post the stack trace corresponding to your crash.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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