2014-05-05 23 views
0

當連續多次觸發某個動作時(基本上有點像啓用StickyKeys),我想要一個通知對話框。我明白,我基本上可以做connect(this->trigger, SIGNAL(triggered()), this, SLOT(onTrigger()))檢測單個觸發器,但我怎麼能檢測到它發生10次?Qt - 動作多次觸發時打開對話框

謝謝。

P.S - 我怎麼能做一個「不再顯示此消息」QCheckBox?

回答

2

您可以實現您通過以下方式插槽:

void MyClass::onTrigger() 
{ 
    static int count = 0; 
    if (count++ == 10) { 
     // show the dialog here 
    } 
} 
+0

我想你錯過了簽名的返回類型。 – lpapp

+0

請重置計數器。 – user2672165

+0

@ user2672165,我沒有看到要求在每個** 10次點擊左右顯示對話框。 – vahancho

0

您需要爲這個外部計數器的連接方法,或QObject的不能爲你做這些外的框。我會寫這個:

MyClass::MyClass(QObject *parent) : QObject(parent), m_cnt(0) 
{ 
    ... 
    // Removed the needless this usage 
    connect(trigger, SIGNAL(triggered()), SLOT(onTrigger())); 
    ... 
} 

void MyClass::onTrigger() 
{ 
    if (m_cnt++ == 10) { 
     m_dialog.show(); 
     // or: m_dialog.exec(); 
    } 
}