Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Help with QLineEdit's slots



  • I have a list of callout objects that are created/displayed on an image. Each of these callout objects contain a QLineEdit object. Each QLineEdit object is connected to it's own signal/slot method. The user can move the mouse around and edit the text in any one of the callouts displayed. In the textEdited signal handler / slot method I want to know which of the callouts I am currently editing in, but all I know is the QString that is passed into it. Any recommendations on how I might be able to do this do this? (This is my first Qt application)


  • Lifetime Qt Champion

    hi and welcome
    Inside a slot you can use the sender() function
    to know which QWidget/QObject that gave/send you the textEdited signal. (or any signal)

    To get the actual QLineEdit, you need to cast it:

    QLineEdit * LineSender=qobject_cast<QLineEdit *>(sender());
    if (LineSender)
    LineSender->xxxx



  • @smoyertech

    Hi and welcome to devnet

    Probably some code highlighting your issue would be helpful.



  • @mrjj Thanks that worked well ...

    QLineEdit * lineSender=qobject_cast<QLineEdit *>(sender());
    foreach(CalloutData *cod, m_calloutList) {
            //qDebug() << lineSender << cod->labelLineEdit();
            if (lineSender == cod->labelLineEdit()) {
                m_currentlySelectedCallout = cod;
                break;
            }
     }
    

  • Lifetime Qt Champion

    @smoyertech
    Super. Im not sure why you have to loop over m_calloutList to find it ? (again?)

    if lineSender != NULL it means it was a LineEdit sending the signal so
    i do wonder why lineSender is not just cod->labelLineEdit ?



  • @mrjj I'm just plugging away right now... The CalloutData objects contain other properties, such as color to indicate whether something has been entered, that need to be modified. That's what they want :)


Log in to reply