如何在另一个类中声明lineEdit
的信号和槽?
LineEdit
类中声明了Peakdetechtion
,我想在peaksettingform
中制作信号和广告位,那我该怎么办?
答案 0 :(得分:0)
QLineEdit必须可以从外部访问(公共或获取),或者您必须转发您感兴趣的信号。
可访问版本(不完整且非常脏)
http://selenium-release.storage.googleapis.com/3.0/selenium-dotnet-3.0.0.zip
信号转发
class Peakdetechtion { // horrible name
public:
QLineEdit* getLineEdit() { return m_lineEdit; } // don't do it
private:
QLineEdit* m_lineEdit;
};
class Peaksettingform : public QObject { //horrible name
Q_OBJECT
public:
Peaksettingform(Peakdetechtion *p, QObject *parent = 0)
: QObject(parent) {
// you can do this from outside and replace 'this' with a pointer to a Peaksettingform object
connect(p->getLineEdit(), SIGNAL(textChanged(const QString &)), this, SLOT(handleText(const QString &)));
}
public slots:
void handleText(const QString &);
};