The problem is in this function:
void test_cast(QObject *returnedObject)
{
QTimer *timer = new QTimer;
timer->setInterval(500);
returnedObject = timer; //<-- changes the returnObject
}
You actually do not change the obj
pointer passed to the test_cast
function, but modify it's copy (returnedObject
). As a result, the obj pointer in the main
function remains uninitialized and your program crashes. To fix this, you need to modify your function in the following way:
void test_cast(QObject **returnedObject)
{
QTimer *timer = new QTimer;
timer->setInterval(500);
*returnedObject = timer;
}
and call this function as:
QObject *obj;
test_cast(&obj);