2016-10-27 3 views

답변

0

QLineEdit 중 하나는 외부에서 액세스 할 수 (일반 또는 취득)해야하거나 관심있는 신호를 전달해야합니다. (불완전하고 아주 더러운)

접근 버전

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

액세스 가능한 버전이 아닙니다. . . 왜 그런지 알아낼 수 있니? @Lifeisabug –

+0

@ GiridhariLal - "wokring"이 아닙니다. 문제의 증상을 설명하십시오. –

+0

내가 제공 한 코드는 분명히 편집 할 수 없습니다. 그것은 그 문제에 어떻게 접근 할 수 있는지에 대한 데모 일뿐입니다. 외부에서 액세스 할 수 있어야하는 메 너스를 직접 편집하거나 외부에서 전달 된 신호에 필요한 신호를 전달할 수 있습니다. – Lifeisabug