QSharedPointer and Temporary Copies

  • Hello,
    I have something like below in my code @void Fun()
    ClassA var = queue->dequeue();

    Now var is a qsharedpointer. From, what i could guess looking into the dequeue function of the QQueue, is that it would return a temporary copy of the var. So, it would increment by 1 the reference count for var and then decrement when it goes out of scope. Can this cause a problem ? Actually, it crashed while doing so. So, i fear, while returning temporary object, the reference counting is going wrong, the actual pointer is being deleted. It is not 100% reproducable
    The architecture is ARM XScale.

  • It's bad practice. I will do it in this way:
    void Foo::bar() {
    MyClass * var = queque->dequeue():

    It's recommended to contains pointers (instead of objects) in containers.

  • You mean to say QSharedPointers cannot be used in containers?

  • can you give a bit more code?
    How is the queue defined? Which types are stored? How are they added?
    This has a big influence on the error...

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.