Reply
Thread Tools
Posts: 190 | Thanked: 129 times | Joined on Mar 2010 @ Bavaria, Germany
#11
Code:
((MainWindow*)parent())->someFunctionDefinedInMainWindow();
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:
Code:
MainWindow* myWindow = qobject_cast<MainWindow*>(someObject);
Code:
void Canvas::refreshFoldersList(QString inputPath)
{
    QDir *dir = new QDir(inputPath);
    dir->setFilter(QDir::AllDirs);
    dir->setSorting(QDir::Name);
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.)
 
Posts: 726 | Thanked: 345 times | Joined on Apr 2010 @ Sweden
#12
And yet again the intricacies of C++ are there to trip you.
 
Reply


 
Forum Jump


All times are GMT. The time now is 22:40.