Reputation: 481
I'm having some trouble, I'm fairly new to Qt and C++ and was testing the waters so to say. Ill try to describe my problem as follows. I have a LineEdit QLineEdit
and this edit has a connection which looks like this:
connect(my_lineedit, SIGNAL (textEdited(QString)),this, SLOT (handleEdits()));
The handleEdits()
method gets called and does the following:
my_lineedit
QLineEdit
which gets a new signal and calls handleAddedEdits()
The stated above works fine Im just telling you this so you get the picture.
Now in the new method which I called handleAddedEdits()
I want kinda the same procedure to happen again.
handleAddedEdits()
from the Edit which invoked this method in the first place.QLineEdit
The problem is: in the first case my_lineedit
is declared in my class so I can freely refer to it and and remove the signal as I wish. In the second case I have a QLineEdit
which was created dynamically in the handleEdits()
method and is the "Sender". My Question is, how can I refer to the "Sender Object" ro remove the Signal from the dynamically created edit?
Upvotes: 4
Views: 7623
Reputation: 2832
You need to use QObject::sender()
method in your receiver's slot:
For cases where you may require information on the sender of the signal, Qt provides the
QObject::sender()
function, which returns a pointer to the object that sent the signal.
handleAddedEdits()
{
QObject* obj = sender();
disconnect( obj, SIGNAL(textEdited(QString)), 0, 0 );
//...
}
Upvotes: 10