sniffi
sniffi

Reputation: 125

How can my Dialog class know which element of the MainWindow has called it

I work with QT-Creator 4.9.1 based on Qt 5.12.3 and I am making a gui for a touch terminal. I have a stacked widget with multiple LineEdit widgets inside on different pages. The problem i have, is that my text from the keyboard should be shown inside the LineEdit of my MainWindow.

Question:

How can I determine which LineEdit called my touchkeyboard and how can i insert the pressed key inside my LineEdit in the MainWindow when my touchkeyboard dialog is modal?

Touch-Keyboard Dialog:

enter image description here

Example for one Stackwidget Page:

enter image description here

Upvotes: 0

Views: 72

Answers (1)

Vahagn Avagyan
Vahagn Avagyan

Reputation: 776

when creating QLineEdit you need set ID , Like that

#include <QLineEdit>
class MyLineEdit : public QLineEdit
{
    Q_OBJECT      
public:
    MyLineEdit(int id = 0, QWidget* parent = nullptr);  
    int id() const;

private: 
    int m_id;   
};


MyLineEdit::MyLineEdit(int id, QWidget *parent)
    :QLineEdit (parent)
    ,m_id(id)
{   
}

int MyLineEdit::id() const
{
    return m_id;
}

after that in the slot you can find out through id which one QLineEdit gave the signal

connect(myLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(customSlot(const QString &)));

or also use lambda expression

connect(myLineEdit, &QLineEdit::textChanged,[this](const QString & txt){

   // Touch-Keyboard Dialog 

});

Upvotes: 1

Related Questions