《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
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信号相关文章推荐
- 翻译Qt4教程:C++ GUI Programming with Qt 4
- C++ GUI Programming with Qt 4 - 10.4 实现自定义代理(delegate)
- C++ GUI Programming with Qt 4 中的信号与槽
- C++ GUI Programming with Qt 4 - 10.3 实现自定义模型
- C++ GUI Programming with Qt 4
- [C++ GUI Programming with Qt 4/5 代码] && [从Qt4过渡至Qt5(The Transition from Qt 4.x to Qt 5)]
- C++ GUI Programming with Qt 4
- C++ GUI Programming with Qt 4 - 10.4 实现自定义代理(delegate)
- 4)(转C++ GUI Programming with Qt 4)~Qt~深入信号槽
- C++ GUI Programming with Qt 3安装说明
- 从第二章开始规范翻译C++ GUI Programming with Qt 4
- C++ GUI Programming with Qt 4 - 10.3 实现自定义模型
- C++ Gui Programming With Qt 4 一到十章汉化的是哪个版本??
- Qt学习书籍:C++ GUI Programming with Qt 4
- 学习C++ GUI Programming with Qt 4遇到的问题(1)
- C++ GUI Programming with Qt3(系列一 试翻)
- 《C++ GUI Programming with Qt 4, Second Edition》读书笔记1
- C++ GUI Programming with Qt 4 - 10.3 实现自定义模型
- Rapid GUI Programming with Python and Qt(1)
- 尝试翻译《Rapid GUI Programming with Python and Qt》