QT document inserted in Chinese, QTextDocument: Doccontentschange() signal contains the first parameter int position not updated.Here are all the test codes
-
==========================================
mainwindow.cpp#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QTextEdit>
#include <QTextDocument>
#include <QTextCursor>
#include <QMainWindow>MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QTextDocument *doc = new QTextDocument;
QTextCursor cur(doc);
QTextEdit *edit = new QTextEdit(this);
connect(doc,&QTextDocument::contentsChange,this,&MainWindow::DocContentsChange);
edit->setDocument(doc);setCentralWidget(edit);
}
MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::DocContentsChange(int aFrom, int aCharsRemoves, int acharsAdded)
{
qDebug() << "aFrom" << aFrom << "aCharsRemoves" << aCharsRemoves << "acharsAdded" << acharsAdded;
}==========================================
mainwindow.h#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void DocContentsChange(int aFrom,int aCharsRemoves,int acharsAdded);private:
Ui::MainWindow *ui;
};#endif // MAINWINDOW_H
==========================================
main.cpp#include "mainwindow.h"
#include <QApplication>int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();return a.exec();
}
-
@jsulm Firstly, create a new QTextDocument object pointer, and the QTextCursor object retrieves the mouse position of the pointer document. Then add a QTextDocument object to the QTextEdit class. Finally, use a signal slot to print the parameters in QTextDocument:: contentsChange. When the document is inserted in English, the positional parameters are updated normally. Insert Chinese position without updating
-
@tonyQQ Could be a bug. You can check whether this was already reported here: https://bugreports.qt.io/secure/Dashboard.jspa
If it was not yet reported you can file a bug there.