I have three windows Mainwindow,firstwindow and secondwindow.I have a pushbutton in mainwindow,When i clicked the push button it opens the firstwindow.Up to this part everything is ok. What i need is , I need to open secondwindow automaticaly after 2sec of the formation of firstwindow
What is happening now is when i clicking the push button in mainwindow, secondwindow will appear first,and the first window will form only after execution of second window.
I am using qt5 with qtcreator
MainWindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_clickMeButton_clicked()
{
FirstWindow * dlg = new FirstWindow;
dlg->show();
}
FirstWindow.cpp
#include "firstwindow.h"
#include "ui_firstwindow.h"
FirstWindow::FirstWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::FirstWindow)
{
ui->setupUi(this);
connect(this,SIGNAL(winMessage()),this,SLOT(openNewWindow()));
emit winMessage();
}
FirstWindow::~FirstWindow()
{
delete ui;
}
void FirstWindow::openNewWindow()
{
dlg = new SecondWindow;
dlg->show();
}
SecondWindow.cpp
**
#include "secondwindow.h"
#include "ui_secondwindow.h"
SecondWindow::SecondWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::SecondWindow)
{
ui->setupUi(this);
}
SecondWindow::~SecondWindow()
{
delete ui;
}
**
emit winMessage();
even beforeFirstWindow
completes its constructor. You have to emit that on a timer (i.e. singleShot) as @user4581301 points out. – Manuel