2

I have a QWidget derivate, let us assume the standard QWidget example

class MainWindow : public QMainWindow { //.. }

Does it make sense for this class MainWindow to fullfill the Rule of Five, I mean especially the Move constructor and move assignment ?

(Since the MainWindow should be created only once)

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ralf Wickum
  • 2,850
  • 9
  • 55
  • 103

1 Answers1

4

Nope. QObject derived classes should never be copied and using the Q_DISABLE_COPY macro QObject and derived classes explicitly disable/hide the copy constructor and assignment operator by declaring them private. Possibly this has changed with recent releases and c++ 11 compatible compilers where they might now be declared deleted. See here

So the Rule of five is out. And looking at the Qt source I can't find any support for moving QObject derived classes ...

One final good read is Qt Objects: Identity vs Value

mikag
  • 162
  • 8