Strange crash with QPointers in a container
-
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?
-
Still no answer where exactly it is crashing and what's the code where it is crashing + backtrace....
-
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!
@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)
-
Still no answer where exactly it is crashing and what's the code where it is crashing + backtrace....
@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?
-
Use a debugger to see where it hangs. I don't see why it should 'hang' because of a pointer in a vector.
-
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" ?
-
Use a debugger to see where it hangs. I don't see why it should 'hang' because of a pointer in a vector.
@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. -
@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. :)
-
@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. :)
@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.