2013-05-21 56 views

回答

2

我看到了這樣做的兩種方式。

複雜:

void MainWindow::showEvent(QShowEvent *e) 
{ 
    QMainWindow::showEvent(e); 
    static bool firstStart = true; 
    if (firstStart) 
    { 
     emit startJob(); 
     firstStart = false; 
    } 
} 

,易一個(只適用,如果你表現出創建後右主窗口):

MainWindow::MainWindow(QWidget *parent) : 
    QMainWindow(parent) 
{ 
    ... 
    QTimer::singleShot(500, this, SLOT(job())); 
} 

更新

Chris說,showEvent在這裏比paintEvent更合適。

+0

糟糕!感謝您的糾正。確實很複雜^ _ ^這就是爲什麼我更喜歡簡單的解決方案。 – Amartel

+0

不能保證簡單的成功,只需創建一個'MainWindow',並且不會顯示它會導致'job()'在初始繪圖發生時運行。 – cmannett85

+1

使用showEvent()代替paintEvent()可能更合適 – Chris