【发布时间】:2011-05-10 16:16:00
【问题描述】:
我对 QT c++ 有疑问
假设这是main.cpp
#include "head.h"
#include "tail.h"
int main()
{
head *head_obj = new head();
tail *tail_obj = new tail();
//some code
}
这里是head.h
class head:public QWidget
{
Q_OBJECT
/* some code */
public slots:
void change_number();
};
这是tail.h
class tail:public QWidget
{
Q_OBJECT
/* some code */
/* some code */
QPushButton *mytailbutton = new QPushButton("clickme");
//this is where i need help
connect(button,SIGNAL(clicked()),?,?);
};
现在我如何将 mytailbutton 的信号 clicked() 连接到头类插槽 change_number? 我只是觉得这不可能。
感谢您的帮助!
【问题讨论】:
-
你是手动删除分配的内存吗?如果没有,那就有问题了。对于 QObject 派生的类,您可以在构造函数中添加一个父对象,它会在销毁时释放其子对象(例如,您要添加
QPushButton的QWidget实例)。