[QScintilla] Changing text during textChanged signal.

Phil Thompson phil at riverbankcomputing.com
Fri Mar 16 10:20:01 GMT 2007


On Thursday 15 March 2007 7:08 pm, you wrote:
> On Thu, 15 Mar 2007 18:32:42 +0100, Phil Thompson
>
> <phil at riverbankcomputing.com> wrote:
> > QScintilla ensures that the document is read/write during the call to
> > setText(). It's possible that the underlying Scintilla code is doing
> > something as there is obvious scope for infinite recursion.
> >
> > Another approach is to update the text next time round the event loop
> > (using
> > QTimer.singleShot() with a 0 timeout).
> >
> > If you can produce a short, complete example that demonstrates the
> > problem
> > then I can take a closer look.
>
> Here some example code.
>
> Header file of my example class:
> ------------------
> #include <QWidget>
> #include <QVBoxLayout>
> #include <Qsci/qsciscintilla.h>
>
> class MainWindow : public QWidget
> {
> 	Q_OBJECT
> public:
> 	MainWindow(QWidget *parent = 0);
> 	QsciScintilla *scintilla;
> public slots:
> 	void textChanged();
> };
> ------------------
>
> cpp file:
> ------------------
> #include "mainWindow.h"
>
> MainWindow::MainWindow(QWidget *parent) : QWidget(parent) {
> 	QVBoxLayout *layout = new QVBoxLayout(this);
>
> 	scintilla = new QsciScintilla(this);
> 	layout->addWidget(scintilla);
>
> 	connect(scintilla, SIGNAL(textChanged()), this, SLOT(textChanged()) );
> }
>
> void MainWindow::textChanged() {
> 	QString str = scintilla->text();
> 	if ( str == "a" )
> 		scintilla->setText("B");
> }
> ------------------
> If the letter "a" is entered, it shoulb be replaced by a "B". But it
> won't. The same works well with QTextEdit.
> Haven't tried your workaround with QTimer yet.

The underlying Scintilla code *does* explicitly prevent reentrant calls. Using 
QTimer gives you the effect you are after.

Phil


More information about the QScintilla mailing list