简体   繁体   中英

QSignalSpy and std::shared_ptr

I would like to test a Qt piece of code that is using signals/slots with std::shared_ptr as parameters.

My issue is that the QSignalSpy class, that works well for all the other type of parameters, does not seem to play nice when it comes to use standard shared pointers. Indeed, the takeFirst method returns a list of QVariant. I can convert the argument to a shared_ptr doing something like that:

QVERIFY(arguments.at(0).value<std::shared_ptr<Canard>>() == canardInstance); // verify the first argument

But then I end up with 2 smart pointers referencing the same heap memory, and it crashes when going out of the current scope. Is there a way to use QSignalSpy in my case ?

Thanks !

Actually I missed completely the point. It was working fine (meaning the reference counting is working as expected) but I got a memory corruption for another reason. I tried using QSharedPointer and get the same behavior.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM