using unique_ptr in qt member variable

332 views Asked by At

i want to use unique_ptr for a QMenu without making it as a child of the base widget so i have declared it like this

private:
std::unique_ptr<QMenu> m_pMenu;

and in constructor

std::unique_ptr<QMenu> m_pMenu ( new QMenu());
m_pMenu->setObjectName("JobContextMenu");

i also added CONFIG += c++11 in my .pro file but when compiling the unique_ptr is returning an error as Invalid application of 'sizeof' to an incomplete type 'QMenu'

1

There are 1 answers

5
UndeadDragon On

Duplicate definition. Also, you can do it in such way in C++ 11:

private:
std::unique_ptr<QMenu> m_pMenu = std::unique_ptr<QMenu>(new QMenu);