The Q_OBJECT macro at the beginning of the class definition is necessary for all classes that define signals or slots
只有加入了Q_OBJECT,你才能使用QT中的signal和slot机制
一个典型的qrc文件
1 <RCC>
2 <qresource prefix="/" >
3 <file>images/brushedmetal.png</file>
4 <file>images/qtlogo-16.png</file>
5 <file>images/branch-closed.png</file>
6 <file>images/branch-open.png</file>
7 <file>images/qphonebutton.png</file>
8 <file>images/update.png</file>
9 <file>images/config.png</file>
10 <file>images/query.png</file>
11 <file>images/live.png</file>
12 <file>images/system.png</file>
13 <file alias="upIcon">images/up.png</file>
14 <file alias="downIcon">images/down.png</file>
15 <file alias="rightIcon">images/right.png</file>
16 <file alias="leftIcon">images/left.png</file>
17 <file>translations/catalog_ch.qm</file>
18 </qresource>
19 </RCC>
而我在代码中使用为liveButton->setIcon(QIcon(":/images/live.png"));
应该在pro文件里加入 RESOURCES += catalog.qrc
嵌入资源的好处是把这些图片也编辑为代码了,可以创建真正独立的可执行文件
代码中按钮的文字没有显示,怀疑是不能显示中文的原因,于是把代码
button = new QPushButton(tr("Seat"));
改为button = new QPushButton("Seat");
可以显示正常了