gpt4 book ai didi

linux - 如何在不同类中编写lineEdit的connect语句

转载 作者:太空宇宙 更新时间:2023-11-04 12:40:46 26 4
gpt4 key购买 nike

如何制作在另一个类中声明的 lineEdit 的信号和插槽?LineEdit 是在 Peakdetechtion 类中声明的,我想在 peaksettingform 中制作信号和插槽,我该怎么做?

最佳答案

QLineEdit 要么必须可以从外部访问(公共(public)或获取),要么您必须转发您感兴趣的信号。

可访问版本(不完整且非常脏)

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 &);
};

信号转发

class Peakdetechtion : public QObject { // horrible name
Q_OBJECT
public:
Peakdetechtion() {
m_lineEdit = new QLineEdit(); // should have a parent but i am lazy
connect(m_lineEdit, SIGNAL(textChanged(const QString&)), this, SIGNAL(leTextChanged(const QString&)));
}

signals:
void leTextChanged(const QString &);

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, SIGNAL(leTextChanged(const QString &)), this, SLOT(handleText(const QString &)));
}

public slots:
void handleText(const QString &);
};

关于linux - 如何在不同类中编写lineEdit的connect语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40279558/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com