I'm fighting with Qt. Cannot find out reliable solution for my specific problem.
We have custom class MyWidget
that must:
- be derived from
QWidget
to overridecloseEvent
method - have fields that must be initialzed in constructor
Problems:
QWidget
's guts initialized withQUiLoader
from.ui
file. So I have onlyQWidget*
pointerQWidget
is non-copyable.QWidget
has no move constructor
The code (error checking and memory management are omitted for simplicity):
class MyWidget : public QWidget
{
bool m_Closed;
public:
MyWidget(QWidget* qw) :
QWidget(*qw), // error: copy constructor is private
m_Closed(false)
{}
bool IsClosed() const { return m_Closed; }
virtual void closeEvent(QCloseEvent *) override { m_Closed = true; }
};
QFile file("main.ui");
QUiLoader uiLoader;
MyWidget* uiMain = new MyWidget(uiLoader.load(&file));
uiMain->show();
Questions:
- How can I workaround this? I feel that solution is very simple.
- Can I use move semantics here somehow?
Note that:
- I cannot make
QWidget
member, as I need to override its method. - Probably, I can make some
MyWidget::Init()
method, to init thosebool
flag, which must be called after each instantiation. But I find this solution unreliable. - In the end, I must just have
QWidget
, that I can check if it was closed or not (maybe you know another, simple way) - I use MSVC 2013 RC and GCC 4.8.1, so C++11 solution would be great
Do not hesitate, I appreciate any suggestions and criticism.