2016-04-30 81 views
0

我必須顯示保存消息框直到超時。 超時發生後,進入插槽並執行一些功能。Qt消息框 - 顯示消息框直到超時

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

上面的代碼是定時器,當超時移動到savinglot時。

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; 
    } 

上面的方法調用其他類,當用戶點擊保存按鈕。 一旦調用該方法,啓動計時器,然後顯示消息框。

如果發生超時調用插槽[如下]

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

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

這個代碼工作,我已經使用了消息框,確定按鈕,當超時創建動畫點擊做一些功能。

現在我想以顯示消息框沒有按鈕,並在超時,然後關閉消息框做了一些功能

但該消息框關閉()不工作。

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

如果我調用上面的代碼消息框必須關閉,但它正在顯示。

任何人都可以幫助我解決這個問題。 在此先感謝。

+1

也許這個頁面的幫助你:[http://stackoverflow.com/questions/2236800/auto-close-qmessagebox](http://stackoverflow.com/questions/2236800/auto-close-qmessagebox) – aghilpro

回答

0

我已經解決了這個問題

used msgBox-> show();而不是msgBox-> exec(); 和msgBox-> hide(); msgBox-> close();

代碼如下。

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; 
    } 
}