Question

so I have made 2 windows, and from my main window I am trying to create a new window when I click on a button

The function I have connected with the button looks like this

void MainWindow::ProfileCreation()
{
CreateProfile cProfile;

cProfile.show();
cProfile.raise();
cProfile.activateWindow();
}

But when I try to click on the button, the window open for like 0,5-1 sec and then closes down again

If i do this in my main.cpp file, where i create MainWindow, it works without problems and shows the window

What should I do to make the window keep showing?

Was it helpful?

Solution

cProfile is a local variable, I don't perfectly know QT but I guess as the variable is destroyed when ProfileCreation exits, the window automatically closes. You'll have to preserve cProfile, either as a class member, a global variable or created on the heap as a pointer.

OTHER TIPS

If your second window is a dialog you can hide the first one and execute the second one.

this->hide();
dialog mainDialog;
dialog.setModal(true);
dialog.exec();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top