Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-123556

QT document inserted in Chinese, QTextDocument::contentsChange() signal contains the first parameter int position not updated..Here are all the test codes

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.12.9, 6.3.0
    • GUI: Text handling
    • None
    • Windows

    Description

      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.

       

      //代码占位符
      ==========================================
      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_OBJECT
        public:
      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();
      } 

       

       

      Attachments

        1. 4.jpg
          4.jpg
          65 kB
        2. 3.jpg
          3.jpg
          68 kB
        3. 2.jpg
          2.jpg
          58 kB
        4. 1.png
          1.png
          187 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            tonyqq liu xu
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes