您的位置:首页 > 编程语言 > C语言/C++

《C++ GUI Programming with Qt 4, Second Edition》读书笔记2

2009-11-11 22:58 543 查看

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行是事件绑定和处理的核心代码。

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

QPushButton提供的signal

ClassSIGNAL说明
QPushButton没有 
  QAbstractButtonclicked

pressed

released

toggled
点击鼠标或者按下快捷键

按钮被按下

按钮被松开

按钮状态变化
    QWidgetcustomContextMenuRequested 
      QObjectdestroyed 
 

QApplication提供的SLOT

ClassSLOT说明
QApplicationaboutQt

autoMaximizeThreshold

autoSipEnabled

closeAllWindows

setAutoautoMaximizeThreshold

setAutoSipEnabled

setStyleSheet
only for Windows CE

only for Windows CE

only for Windows CE

only for Windows CE
  QCoreApplicationquit 
    QObjectdeleteLater 
 

后续工作

写个例子来使用pressed/released/toggled信号
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: