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. Strange crash with QPointers in a container
Forum Updated to NodeBB v4.3 + New Features

Strange crash with QPointers in a container

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 5 Posters 1.2k Views 2 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.
  • A aart

    It's even stranger than I thought:

    having this is allowed:

        QPointer<BaseTOP> a;
        QPointer<BaseTOP> b;
        QPointer<BaseTOP> c;
        QPointer<BaseTOP> d;
        QPointer<BaseTOP> e;
    

    But this is not:

    std::array<QPointer<BaseTOP>, 4> test;
    

    What is going on here?

    Pl45m4P Offline
    Pl45m4P Offline
    Pl45m4
    wrote on last edited by
    #3

    @aart

    Hi,

    when does it crash? Where do you initialize your class objects?


    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

    ~E. W. Dijkstra

    A 1 Reply Last reply
    0
    • Pl45m4P Pl45m4

      @aart

      Hi,

      when does it crash? Where do you initialize your class objects?

      A Offline
      A Offline
      aart
      wrote on last edited by
      #4

      @Pl45m4
      I have a single threaded application, i create the objects in QGraphhicsView's mouseDoubleClickEvent function. Nothing strange i can think of ...

      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #5

        Still no answer where exactly it is crashing and what's the code where it is crashing + backtrace....

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        A 1 Reply Last reply
        0
        • A aart

          I'm developping an application where instances of an abstract base class need to keep references to other instances of the same base class. I thought to use Qpointers for that to avoid any possible dangling pointers. But for some reason everything I try results in the application freezing and windows telling me the application is not responding.

          This is where it goes wrong:

          class SomeClass : public QObject{
          Q_OBJECT
          public: 
              ...
          protected:
              QVector<QPointer<SomeClass>> test{ 3 }; 
          }
          

          I have tried multiple container classes: vector QVector QList , all of them result in the application freezing. I'm quite new to Qt. is THere something I'm doing wrong here? Am I making some mistake with my usage of QPointer?

          Thanks in advance!

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by
          #6

          @aart said in Strange crash with QPointers in a container:

          This is where it goes wrong:

          class SomeClass : public QObject{
          Q_OBJECT
          public:
          ...
          protected:
          QVector<QPointer<SomeClass>> test{ 3 };
          }

          I dont think that this is the part of your code where it crashes :)
          Where do you push the objects in your vector? Where do you try to access them / use the pointers?
          Without any code, nobody can help you.

          @aart said in Strange crash with QPointers in a container:

          QVector<QPointer<SomeClass>> test{ 3 };

          This doesnt look wrong (QVector, Lenght 3, with QPointers to SomeClass-object)


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          2
          • Christian EhrlicherC Christian Ehrlicher

            Still no answer where exactly it is crashing and what's the code where it is crashing + backtrace....

            A Offline
            A Offline
            aart
            wrote on last edited by
            #7

            @Christian-Ehrlicher The thing is that it doesnt actaully crash but just gets stuck and stops responding, I cant really post all the code here because that would be way too much. Is there any way i can get some sort of error log that people can get information out of?

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #8

              Use a debugger to see where it hangs. I don't see why it should 'hang' because of a pointer in a vector.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              A 1 Reply Last reply
              3
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #9

                Hi
                I tried your SomeClass in a small project but nothing happened.
                Im not really sure its related to QPointer as there is no reason why it should
                do odd stuff. Code seems pretty normal.

                Do you have s small sample that will produce the "odd part" ?

                1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  Use a debugger to see where it hangs. I don't see why it should 'hang' because of a pointer in a vector.

                  A Offline
                  A Offline
                  aart
                  wrote on last edited by
                  #10

                  @Christian-Ehrlicher
                  Okay so using the debugger i found where the problem lays. I'm very new to qt and qt creator, so i didnt understand how to use the debugger :p The issue was indeed not in the class with the vector but elsewhere in the code where i was using the data stored in the vector. Thanks for the help everyone. The thread can be closed.

                  1 Reply Last reply
                  1
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #11

                    @aart said in Strange crash with QPointers in a container:

                    The thread can be closed.

                    This can be done by you by editing the first post and setting it to resolved. :)

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    aha_1980A 1 Reply Last reply
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      @aart said in Strange crash with QPointers in a container:

                      The thread can be closed.

                      This can be done by you by editing the first post and setting it to resolved. :)

                      aha_1980A Offline
                      aha_1980A Offline
                      aha_1980
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      @Christian-Ehrlicher said in Strange crash with QPointers in a container:

                      @aart said in Strange crash with QPointers in a container:

                      The thread can be closed.

                      This can be done by you by editing the first post and setting it to resolved. :)

                      No, just use the button Topic Tools. There is an entry Mark as Resolved.

                      Qt has to stay free or it will die.

                      1 Reply Last reply
                      1

                      • Login

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