PDA

View Full Version : Show initial widget, best solution?



martinn
26th February 2010, 14:09
In the application I'm building I need the user to input some information the first time he open the application. So in the widget that is my QMainWindow I checks if the data has been created, otherwise I need to show another widget (SetupView) for the user so he can enter the data. The rest of the application is all in MainWidget.

In the code I'm using now the problem is that the SetupView shows up first as I set it to showMaximized but then right after I use w.showMaximized to show my MainWidget so the SetupView will not show. Can I make the SetupView show up inside MainWidget instead? I should always show the MainWidget fullscreen as this is the main window of the application right?

I am not sure how to make a good solution out of this, but you can see the code below and maybe you find it simplier than me. I have been working with this all morning but can't figure out the best way. What is your idea? Thanks!

In main.cpp:


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWidget w;
w.showMaximized();
return a.exec();
}


In MainWidget.cpp:


MainWidget::MainWidget(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);

DataHolder *data = new DataHolder();
if(!data->hasData())
{
SetupView *setupView = new SetupView();
setupView->showMaximized();
}
}

Lykurg
26th February 2010, 14:53
A "simple" workaround would be if you check the DataHolder in your main function before initialising you r main window. (if that is possible with your data management. One possibility could therefore be to use a singleton pattern.)

Lesiok
26th February 2010, 16:49
Try something like this :

MainWidget::MainWidget(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
QTimer::singleShot( 0, this, SLOT(checkSetup()) );
}

void MainWidget::checkSetup(void)
{
DataHolder *data = new DataHolder();
if(!data->hasData())
{
SetupView *setupView = new SetupView();
setupView->exec();
}
}

SetupView will be showed so fast as possible and block rest of application.