Please never ever do something like this! If you want to use your class inside Canvas, make a property. Never expect canvas to be always a child of your MainWindow.
Secondly, you're writing c++ code, not c - so use the c++ casts or your Qt favourite cast like:
Better make this a stack variable, you're leaking memory without any sense.
Please be also aware of passing your this pointer from your class' constructor. This may lead to problems when using derived classes. (The this pointer points to a memory fragment of the class whose constructor you are in. This means in your MainWindow::MainWindow(), this points to the vtable of MainWindow. In QMainWindow::QMainWindow(), this points to the vtable of QMainWindow. In every other function except constructors and destructors the this pointer always points to the vtable of your derived class - MainWindow in your case.)
Secondly, you're writing c++ code, not c - so use the c++ casts or your Qt favourite cast like:
Please be also aware of passing your this pointer from your class' constructor. This may lead to problems when using derived classes. (The this pointer points to a memory fragment of the class whose constructor you are in. This means in your MainWindow::MainWindow(), this points to the vtable of MainWindow. In QMainWindow::QMainWindow(), this points to the vtable of QMainWindow. In every other function except constructors and destructors the this pointer always points to the vtable of your derived class - MainWindow in your case.)