《C++ GUI Programming with Qt 4, Second Edition》讀書筆記2

Chapter 1 Getting Started / Making Connections

 

signal/slot機制

本小節講述的是QT特有的signal/slot機制。

代碼如下:

   1:  #include <QApplication>
   2:  #include <QPushButton>
   3:   
   4:  int main(int argc, char *argv[])
   5:  {
   6:      QApplication app(argc, argv);
   7:  //    QPushButton *button = new QPushButton("Quit");
   8:  //    QObject::connect(button, SIGNAL(clicked()), &app, SLOT(quit()));
   9:  //    button->show();
  10:   
  11:      QPushButton button("Quit");
  12:      QObject::connect(&button, SIGNAL(clicked()), &app, SLOT(quit()));
  13:      button.show();
  14:   
  15:      return app.exec();
  16:  }

其中,第12行是事件綁定和處理的核心代碼。

QPushButton提供的signal

Class SIGNAL 說明
QPushButton 沒有  
  QAbstractButton clicked
pressed
released
toggled
點擊鼠標或者按下快捷鍵
按鈕被按下
按鈕被鬆開
按鈕狀態變化
    QWidget customContextMenuRequested  
      QObject destroyed  

 

QApplication提供的SLOT

Class SLOT 說明
QApplication aboutQt
autoMaximizeThreshold
autoSipEnabled
closeAllWindows
setAutoautoMaximizeThreshold
setAutoSipEnabled
setStyleSheet

only for Windows CE
only for Windows CE

only for Windows CE
only for Windows CE
  QCoreApplication quit  
    QObject deleteLater  

 

後續工作

寫個例子來使用pressed/released/toggled信號

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章