//maiwindow.h#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QtGui>#include <QMainWindow>#include <QPlainTextEdit>#include <QAction>#include <QByteArray>#include <QLabel>#include <QErrorMessage>QT_BEGIN_NAMESPACEclass QPlainTextEdit;QT_END_NAMESPACEclass MainWindow : public QMainWindow{ Q_OBJECTpublic: MainWindow(QWidget *parent = 0); ~MainWindow(); QByteArray buf; QErrorMessage lbl;private: QPlainTextEdit *textEdit;private slots: void myslot() { lbl.showMessage("hhh"); lbl.exec(); //delay 5 sec for(int i=0;i<buf.size();i++) { if (buf.at(i) == '1') buf = '2'; } }};#endif // MAINWINDOW_H---------------------//mainwindow.cpp#include "mainwindow.h"MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ buf.resize(1000); textEdit = new QPlainTextEdit(buf); setCentralWidget(textEdit); connect(textEdit->document(),SIGNAL(textChanged()),this,SLOT(myslot()));}MainWindow::~MainWindow(){;}//////fffffaaccccc/* if( textEdit->canPaste()) { lbl.showMessage("hhh"); // lbl.exec(); //delay 5 sec for(int i=0;i<buf.size();i++) { if (buf.at(i) == 'a') buf = 'b'; } } */-------------------------//main.cpp#include "mainwindow.h"#include <QApplication>int main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow w; w.show(); return a.exec();}
if (buf.at(i) == '1') buf = '2';
#ifndef TESTPLAIN_H#define TESTPLAIN_H#include <QtWidgets/QMainWindow>#include <QPlainTextEdit>#include "ui_testplain.h"class testPlain : public QMainWindow{ Q_OBJECTpublic: testPlain(QWidget *parent = 0); ~testPlain();private: Ui::testPlainClass ui; QPlainTextEdit * textEdit; bool work;private slots: void mySlot() { if (!work) { work = true; QString content = textEdit->toPlainText(); content.replace("a", "b"); textEdit->clear(); textEdit->appendPlainText(content); work = false; } }};#endif // TESTPLAIN_H
#include "testplain.h"testPlain::testPlain(QWidget *parent) : QMainWindow(parent){ ui.setupUi(this); textEdit = new QPlainTextEdit; work = false; setCentralWidget(textEdit); connect(textEdit,SIGNAL(textChanged()),this,SLOT(mySlot()));}testPlain::~testPlain(){}
#ifndef TESTPLAIN_H#define TESTPLAIN_H#include <QtWidgets/QMainWindow>#include <QPlainTextEdit>#include <QDebug>#include <QTextCodec>#include <QChar>#include <QTextStream>#include <string.h>#include <stdlib.h>class testPlain : public QMainWindow{ Q_OBJECTpublic: testPlain(QWidget *parent=0); ~testPlain();private: QPlainTextEdit * textEdit; bool work; QString content; QByteArray bf; int transform_content(QString &content);private slots: void mySlot() { if (!work) { content=textEdit->toPlainText(); work = true; // QTest::qWait(10000); transform_content(content); textEdit->clear(); textEdit->setPlainText(content); } }};#endif // TESTPLAIN_H//=======================#include "mainwindow.h"testPlain::testPlain(QWidget *parent) : QMainWindow(parent){ textEdit = new QPlainTextEdit; bf.resize(1000); work = false; setCentralWidget(textEdit); connect(textEdit,SIGNAL(textChanged()),this,SLOT(mySlot()));}testPlain::~testPlain(){}int testPlain::transform_content(QString &content){ int i,j; bf=content.toLocal8Bit(); i=bf.size(); float par1,par2,par3,par4,par5,par6,z1,z2,z3;//,a,b; j=0; for(i=bf.size();i>0;i--) { if( qstrncmp( "tion",bf.data()+i,4)==0 && !j) { j++; i--; } if( qstrncmp( "tion",bf.data()+i,4)==0 && j==1) {; sscanf((char*)(bf.data()+i),"tion %f %f %f %*s",&par1,&par2,&z1); j++; i--; } if( qstrncmp( "tion",bf.data()+i,4)==0 && j==2) { sscanf((char*)(bf.data()+i),"tion %f %f %f %*s",&par3,&par4,&z2); j++; i--; } if( qstrncmp( "tion",bf.data()+i,4)==0 && j==3) { j++; i--; } if( qstrncmp( "tion",bf.data()+i,4)==0 && j==4) { sscanf((char*)(bf.data()+i),"tion %f %f %f %*s",&par5,&par6,&z3); j++; i--; } if(j==5) break; } bf.clear(); QTextStream(&bf)<<"par1"<<par1; content.clear(); content.prepend(bf); return 0;}//========================================#include "mainwindow.h"#include <QApplication>int main(int argc, char *argv[]){ QApplication a(argc, argv); testPlain w; w.show(); return a.exec();}