Question

I have a MainWindow class and Another class. Another class has method createView that create new QGraphicsView. This method I call from MainWindow and I also want to layout this view on my form. It looks like:

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)) {
       ...
       AnotherClass object(this);
       object.createView();
       ...
}
...
void AnotherClass::createView() {
       QGraphicsView *gv= new QGraphicsView(mainWindow); // mainWindow - pointer to MainWindow object
       gv->show();
}

But it doesn't work so good... actually it does't work at all. And yes, I save pointer on MainWindow object in my Another class as mainWindow, that I take from Another class constructor. If use

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)) {
       ...
       QGraphicsView *gv= new QGraphicsView(this); 
       gv->show();
       ...
}

It will work fine, but this solution doesn't satisfied me.

Was it helpful?

Solution

Problem was in creating variable on stack.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top