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

currentTextChanged missing SIGNAL(s) sequence ?



  • This is a follow-up on another post.
    Very simple question.
    The Bluetooth scanner "Nearby BT devices" list gets filled via function in original example "btscanner" ( I did not write nor checked the XML code ) .
    Works as expected , but in reverse of similar scan used by "Blueman" "Device search". See f-SATA device.

    My objective is to use "currentTextChanged" SIGNAL to copy the items in
    "Nearby BT devices" list elsewhere.
    It works , but copies only the LAST item from "Nearby BT devices" list.

    It is no big loss, I can copy it manually , but like to know

    1. how is "current" text defined ? ( index 0 ??)
    2. why am I missing all but one "currentTextChanged" SIGNAL ?
    connect( DDD->ui->list,
             SIGNAL( currentTextChanged( const QString & ) ),
            this->ui->plainTextEdit_2,
             SLOT( appendPlainText( const QString & ) )
             );
    
    

    abe51a7a-a9de-479a-9bcc-663d267fe513-image.png


  • Moderators

    What is your "list"? A QListWidget?

    @AnneRanch said in currentTextChanged missing SIGNAL(s) sequence ?:

    how is "current" text defined ? ( index 0 ??)

    Current row property is defined as such: https://doc.qt.io/qt-5/qlistwidget.html#currentRow-prop

    And current text: https://doc.qt.io/qt-5/qlistwidget.html#currentTextChanged

    This is flexible, but can be broadly abbreviated to: current row is the selected row (by mouse or keyboard).

    why am I missing all but one "currentTextChanged" SIGNAL ?

    I don't know what you've got, the screenshot is completely unclear to me. Please post what you expect vs. what you've got.

    Are you changing the current row anywhere? If your goal is to populate one list based on contents of another, using currentText property is a very awkward approach. You should rather respond to signals emitted by your model(), like rowsInserted(), rowsRemoved(), modelReset().



  • @sierdzio I am asking how is "current" defined.
    Assuming the widget can hold indexed items - is "current " at index 0 ?
    Or is it the one highlighted by positioning the mouse over it ? Clicking it?

    "This is flexible, but can be broadly abbreviated to: current row is the selected row (by mouse or keyboard)."

    Just a definition of "current" is what I need because the function is filling the widget - there is no manual , by user (mouse / keyboard) , selection during fill.

    After that is clarified I may be able figure out why only LAST SIGNAL is acted upon .
    But I need to know what to monitor as "current".

    As far as "awkward" - the fill is dynamic and using "row" requires knowing the start / end. My way is KISS.


  • Lifetime Qt Champion



  • @Christian-Ehrlicher said in currentTextChanged missing SIGNAL(s) sequence ?:

    @AnneRanch said in currentTextChanged missing SIGNAL(s) sequence ?:

    Just a definition of "current" is what I need

    See https://doc.qt.io/qt-5/model-view-programming.html#current-item-and-selected-items

    Using the above definitions - there is no current anything AFTER the widget is filled.

    Tracing the "add item" functions confirms that only first item "appended" to the widget is generating currentTextChanged SIGNAL for further processing,
    My guess is "current item" is indeed at index 0 and DOES not change - next items are appended - hence no more SIGNAL will be generated.

    Time to find a different way to skin the cat.


  • Moderators

    @AnneRanch said in currentTextChanged missing SIGNAL(s) sequence ?:

    Tracing the "add item" functions confirms that only first item "appended" to the widget is generating currentTextChanged SIGNAL for further processing,
    My guess is "current item" is indeed at index 0 and DOES not change - next items are appended - hence no more SIGNAL will be generated.

    Why "guess"? The documentation clearly says that current item changing is a result of user interaction (click, double click, keyboard arrow click, etc.). Adding or removing rows won't change it (except for adding first or removing last item - then obviously the text changes).

    Time to find a different way to skin the cat.

    As mentioned, use model() for this. It informs you exactly what, where, and how is changed. And if you want to do it simple, you can just clear your other view and load it afresh every time the model is changed.



  • @sierdzio
    OK, since you continue to re-post same argument you won't mind if I re-post mine, right?

    Why am I getting ONLY one of minimal four signals?

    Before I try model, I will "connect" to process "scan" which by the way detects non-existent bluetooth devices and passes them to the function filling the list - hence I need to fix that first anyway. ( Nothing to do with this post !)



  • @AnneRanch said in currentTextChanged missing SIGNAL(s) sequence ?:

    Why am I getting ONLY one of minimal four signals?

    Because, as per the definition of "current" text given by @sierdzio above, the current text only changes when the first item is added. That's how it works. So only one raising of the signal. You will need to pick a different signal to listen for, one emitted by the model instead.


  • Moderators

    OK, since you continue to re-post same argument you won't mind if I re-post mine, right?

    Sure, as long as we reach some understanding in the end, that is fine.

    @AnneRanch said in currentTextChanged missing SIGNAL(s) sequence ?:

    Why am I getting ONLY one of minimal four signals?

    You only change current item once (implicitly) - first when model is empty, currentText() == "". then when you add first item, currentText changes to the text of that item.

    Then, as you keep adding more rows, currentItem does not change - it waits for user interaction to happen (or you can force it to change programmatically by changing currentItem when new row is inserted).

    This all works exactly as documented in the docs I've linked.



  • @sierdzio said in currentTextChanged missing SIGNAL(s) sequence ?:

    Sure, as long as we reach some understanding in the end, that is fine.

    first when model is empty, currentText() == "". then when you add first item, currentText changes to the text of that item. AGREED

    Then, as you keep adding more rows, currentItem does not change AGRRED which is why I posted this originally - it waits for user interaction AGREED , BUT THERE IS NO USER INTERACTION - AS CODED - to happen (or you can force it to change programmatically by changing

    SOLVED


Log in to reply