How to get an event / change when text / item changes.
-
this is a repost of very old question which then never got resolved .
I like to get another run at it , before i embark on anther wild goose chase.The original question is now little modified - due to some (gained) experience :
I have a (item /text/line) widgets whose lines are being filled by external process. Attached.
My task is to copy / transfer each (item / text /line ) to similar widget.
( This is not stupid way , just test of concept)
I have found at lest two distinct widgets to do this , one uses text and the other item. I can deal with that - no problem and that is i NOT my question.The original and same question is
there is no user interaction with the text / item being added ( by attached function) to these widgets. NONE - no mouse , keyboard . laser pointer - nothing !
so are these identified as "current text / item " or "changed text / item " .It seem that each widget has different point of view as far as "generic change ".
That is OK, but point of (MY) concern - "current " seems to be reserved when text / item is actually physically selected / highlighted - which is NOT my case.
I realize this is little convoluted , but the key is - the text/ item appears in the widget and I need to detect that event , no matter what it is called.
( Yes , I did checked the docs)Here is a "test TRACE " generating function putting text / item to corresponding widgets
qDebug() << Q_FUNC_INFO; ui->chat_3->setText(Q_FUNC_INFO); // clear and addr QTextEdit ui->listWidget->clear(); // clear QListWidget for ( int index = 0; index < 10; index++) { ui->chat_3->append(Q_FUNC_INFO ) ; // text ui->listWidget->addItem(Q_FUNC_INFO); //item }
-
Since you add it to those widgets you can also emit a signal with the appended/new text there and do whatever you want with this.
-
Since you add it to those widgets you can also emit a signal with the appended/new text there and do whatever you want with this.
@Christian-Ehrlicher OK if I can manage to display all available options to detect the event - I'll post it here so you can suggest the actual option .
EDIT / ADD
As I said - I am using two widgets to test. QTextWidget and QListWidget .
Here are my similar "go to slot " functions .
The QTextWidget responds as desired to "textChanged".
The QListWidget DOES NOT generate "currentTextChanged" - I am assuming the "current" is when there is user interaction with the "item". I am not interested in that option, hence not verified.
It seems that one has to be careful when QListWidget is used to monitor plain text , after all QListWidget handles "items" not text specifically.Unless there are more contributions I consider this closed - solved.
// fill respose QTextWidget TOK void TabWidget_Chat::on_chat_3_textChanged() { qDebug() << Q_FUNC_INFO; int static index ; // fill response trace // QString concatenate QString trace =Q_FUNC_INFO; trace.append(" index # " + QString::number(index)); // ui->chat_3->append(trace ) ; // text ui->listWidget_2->addItem(trace); // index++; } // fill response QListWidget not detected void TabWidget_Chat::on_listWidget_currentTextChanged(const QString ¤tText) { qDebug() << Q_FUNC_INFO; int static index ; // fill response trace // QString concatenate QString trace = currentText ; // Q_FUNC_INFO; trace.append(" index # " + QString::number(index)); // ui->chat_3->append(trace ) ; // text ui->listWidget_2->addItem(trace); // index++; }