多窗口信号传递出问题了
假设A,B两个窗口
在A中定义了一个信号
signals:
void explains();
void emit_date(QString str);
当获得A窗口的输入值date以后,用 emit emit_date(date);将该值返回
A中用connect(B, emit_date(QString), this, SLOT(get_date(QString)));连接信号和槽
调试发现B确实发出了一个信号,但是A中缺无法获得,何解?
补充点代码:
class GoToCellDialog : public QDialog
{
Q_OBJECT
public:
GoToCellDialog(QWidget *parent = 0);
QString date;
Ui::GoToCellDialog ui;
private slots:
void get_date();
signals:
void explains();
void emit_date(QString str);
};
以上是子窗口的.h文件
GoToCellDialog::GoToCellDialog(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
connect(ui.okButton, SIGNAL(clicked()), this, SLOT(get_date()));
}
这个是子窗口的.cpp
void GoToCellDialog::get_date()
{
date = ui.date->text();
ui.check_it->setText(date);
emit emit_date(date);
}
);
子窗口的槽,获得的date检查木有问题
PS:这个槽调用完了,怎么退出QDialog啊?
是不是的“okButton”连接一个退出的槽?
connect(dialog, SIGNAL(emit_date(QString)), this, SLOT(Get_date(QString)))
父窗口信号连接
void testMainWin::Get_date(QString str)
{
date = str;
}
父窗口的槽
解决方法:
void testMainWin::Date_input()
{
GoToCellDialog* dialog;
dialog = new GoToCellDialog;
dialog->exec();
date = dialog->date;
}
直接调用子类的属性,子类执行后竟然没有被析构。
[ 此帖被destiny在2010-01-21 01:10重新编辑 ]