0

I have to show the saving message box until timeout. Once the timeout happens go to slot and do some function.

timerToSave=new QTimer(this);
connect(timerToSave,SIGNAL(timeout()),this,SLOT(SavingStatusSlot()));

Above code is the timer, when timeout moves to the saveslot.

bool PopUpManager::PopUpSaveStaus()
    {
        timerToSave->start(3000);
        saveStatus=false;
        if(SetThread::getInstance()->UISaveStatus==ST_PROCESSING)
        {
            msgBox = new QMessageBox(0);
            msgBox->setModal(true);
            msgBox->setText("Saving ... ");
            msgBox->setIcon(QMessageBox::Information);
            msgBox->setStandardButtons(QMessageBox::Ok);
            msgBox->setCursor(Qt::WaitCursor);
            msgBox->setWindowFlags(Qt::FramelessWindowHint| Qt::WindowStaysOnTopHint);
            msgBox->setStyleSheet("background-color:#444;color:#FFF;outline:none;");
            msgBox->exec();
        }
        else
             SavingStatusSlot();
        return saveStatus;
    }

Above method called from other classes, when the user click on the save button. once the method called, starting the timer then displaying the message box.

if timeout happens calling slot [given below]

    void PopUpManager::SavingStatusSlot()
    {
        msgBox->button(QMessageBox::Ok)->animateClick();
        timerToSave->stop();

        if(SetThread::getInstance()->UISaveStatus==ST_OK)
        {
            saveStatus=true;
        }
        else 
        {
            PopUpWithOKButton(" Saving Error ");
            saveStatus=false;
        }
    }

this code is working, I have used the message box with OK button and when the timeout creating the animated click and doing some function.

Now I want to show the Message box without button and when timeout, close the message box then do some function

But the Message box close() is not working.

void PopUpManager::ClosePopUP()
{
    if(msgBox->isEnabled())
        msgBox->close();
}

if I call the above code the message box has to close, but it is displaying.

Can anyone help me on this. Thanks in advance.

tharunkumar
  • 2,801
  • 1
  • 16
  • 19
  • 1
    maybe this page help you: [http://stackoverflow.com/questions/2236800/auto-close-qmessagebox](http://stackoverflow.com/questions/2236800/auto-close-qmessagebox) – Farhad Apr 30 '16 at 10:11

1 Answers1

0

I have solved the issue

used msgBox->show(); instead of the msgBox->exec(); and msgBox->hide(); insted of msgBox->close();

code is given below.

bool PopUpManager::PopUpSaveStaus()
{

    timerToSave->start(3000);

    saveStatus=false;
    if(UISaveStatus==ST_PROCESSING)
    {
        msgBox = new QMessageBox(QMessageBox::Information,"Error","Processing ... ",0,0,Qt::FramelessWindowHint| Qt::WindowStaysOnTopHint);
        msgBox->setStandardButtons(0);
        msgBox->setCursor(Qt::WaitCursor);
        msgBox->setStyleSheet("background-color:#444;color:#FFF;outline:none;");
        msgBox->show();
    }
    else
    {
         SavingStatusSlot();
    }
    return saveStatus;
}

void PopUpManager::SavingStatusSlot()
{
    msgBox->hide();
    timerToSave->stop();

    if(UISaveStatus==ST_OK)
    {
        saveStatus=true;
    }
    else
    {
        PopUpWithOKButton(" communication Failed ");
        saveStatus=false;
    }
}
tharunkumar
  • 2,801
  • 1
  • 16
  • 19