在我的代碼中的一些問題,我有:智能指針和QThread的問題
QThread* thread = new QThread;
Beacon *beacon = new Beacon(beg, end);
beacon->moveToThread(thread);
而且有一天,我正在讀這個東西叫做智能指針。如果我的理解,它可能適合在上面代碼的和平,我想:
std::unique_ptr<QThread> thread {new QThread};
std::unique_ptr<Beacon> beacon {new Beacon(beg, end)};
beacon->moveToThread(thread);
這導致:
error: no viable conversion from 'std::unique_ptr<QThread>' to 'QThread *'
beacon->moveToThread(thread);
有什麼不對?
'moveToThread(thread.get())' –