QplaintextEdit Paste problem of memory



  • Hello,

    Is it normal that QPlaintextEdit moreover optimized as TextEdit is very slow when you copy a text such as a code of 1,000,000 lines or sometimes right clic application it takes 2 minutes to copy everything and after modifying this text is slow, and animation windows and also very slow and takes a lot of processor memory. someone an explanation for that? or solution?

    Thank you.


  • Qt Champions 2016

    Hi
    Well it's not as fast as a native text edit it seems.
    it get slow around 100.000 here
    on win 7. so 1 million lines would make it hang for long time.
    (on my machine at least)

    void MainWindow::on_pushButton_released()
    {
        ui->plainTextEdit->setUpdatesEnabled(false);
        for (long int var = 0; var < 100000; ++var) {
        ui->plainTextEdit->insertPlainText(QString::number(var)+"\n");
        }
        ui->plainTextEdit->setUpdatesEnabled(true);
    }
    


  • @mrjj yes ca takes a long time to load and notepad ++ is really fast and ca not take much memory. what's the function do ?


  • Qt Champions 2016

    @Aouache
    the function just add 100 000 lines to a plaintext
    to speed it up slightly it disables redraw while it adds.
    setUpdatesEnabled turns of/on redraws.



  • @mrjj thanks you but thert is a nother problem, it takes a lot of memory, you think that there are two different methods, one that handles data and another for rendering.


  • Qt Champions 2016

    @Aouache
    yeah it has. It has support for paragraphs with more so maybe it is the creation of those that takes all that memory.
    It won't handle 1 million lines very well.
    Can I ask what you are trying to program?
    A source code editor?



  • @mrjj No it's a program billing for to a shop they need à software


  • Qt Champions 2016

    @Aouache
    Ok. so why do you have 1 million lines textedit?
    Will they have that many bills or ?



  • @mrjj there have bills into pages that may contain 800,000 to lines and wanted to know if it is possible to display only one time in a qplaintextedit with formatting without separating and without the programe takes a lot of memory.


  • Qt Champions 2016

    @Aouache
    I think it will take a lot of memory for 800.000 lines.
    If you save it as file with notepad++, what is file size then?

    Do they need to edit it? a QListWIdget will handle it better, scrolling etc
    but still memory though.



  • @mrjj QListWIdget ok I'll try and I would keep you informed if it's work thanks


  • Qt Champions 2016

    @Aouache
    how long is each line ?
    very long or just a few letters?
    When loaded, what to they want to do with it?



  • @mrjj a line contains approximately 150 characters. There are two modes is read only opening a file and the other editable (copy, paste, edit the text). I found a solution for Qplainttextedit. is to fix each qplaintexteedit 50,000 lines after them within a QScrollArea and amending stylsheet I can bring them closer and make him look like a single qplaintextedit. that's what I wanted to create a QThread that handles data copied from a program and insert it in a QTextDocument before displaying it in ca Qplaintextedit is the role of my thread but I have two problems:

    the first is when I copy a text and I stick it in my application displays this message with me debug thread:

    "thread lancer.....
    
    QObject::connect: Cannot queue arguments of type 'QTextBlock'
    
    (Make sure 'QTextBlock' is registered using qRegisterMetaType().)
    
    QObject::connect: Cannot queue arguments of type 'QTextCursor'
    
    (Make sure 'QTextCursor' is registered using qRegisterMetaType().)
    
    thread terminer.....  "
    

    even it works when I have the text displayed in my application and the second concern is when I try to paste another text or the same text before. the appilcation plant by displaying this message:

    "ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread aa869744c0. Receiver '' (of type 'QTextDocument') was created in thread aa846a1400", file kernel\qcoreapplication.cpp, line 553".
    

    any idea ?


  • Qt Champions 2016

    @Aouache said:
    Hi thank you for the info.

    Cannot send events to objects owned by a different thread

    Well you are not allowed to use Gui things from other threads.
    You must use the worker approach described here
    http://doc.qt.io/qt-5.5/qthread.html#details

    If you google it, its a common issue.

    Would it be possible for the other program to save it to file?



  • @mrjj its not working what you showed me the example of QThread he always shows me the same bug:

    "thread lancer.....
    
    QObject::connect: Cannot queue arguments of type 'QTextBlock'
    
    (Make sure 'QTextBlock' is registered using qRegisterMetaType().)
    
    QObject::connect: Cannot queue arguments of type 'QTextCursor'
    
    (Make sure 'QTextCursor' is registered using qRegisterMetaType().)
    
    thread terminer.....  "
    

    after it crashes.

    this is my code of my thread pastethread.cpp :

    #include "pastethread.h"
    #include <QDebug>
    
    PasteThread::PasteThread(QObject* parent):
        QThread(parent)
    {
        mydata = new QMimeData();
    }
    
    PasteThread::~PasteThread()
    {
    //    exit();
    //    wait();
    
    //    mydata = NULL;
    //    myedit = NULL;
    
    //    delete mydata;
    //    delete myedit;
    }
    
    void PasteThread::run()
    {
    
        qDebug()<<"thread lancer.....";
    
        QByteArray data = mydata->data(mydata->formats().first());
    
        QTextDocument *dd = new QTextDocument();
    
        dd = myedit->document();
    
        QTextStream *stream = new QTextStream(&data);
    
        dd->setPlainText(stream->readAll());
    
        emit Send_data(dd);
    
    }
    
    

    this my code of document dockshow.cpp

    #include "dockshow.h"
    #include <QDebug>
    #include <QApplication>
    
    Dockshow::Dockshow(QWidget *parent) :
        QPlainTextEdit(parent)
    {
    
    }
    
    void Dockshow::startWorkInAThread()
    {
    
        mythread = new PasteThread(this);
    
        mythread->mydata = tt;
        mythread->myedit = this;
    
        connect(mythread, &PasteThread::Send_data, this, &Dockshow::Get_data);
        connect(mythread, &PasteThread::finished, mythread, &QObject::deleteLater);
    
        mythread->start();
    }
    
    void Dockshow::insertFromMimeData(const QMimeData *data)
    {
        tt = new QMimeData();
        tt = const_cast<QMimeData*>(data);
    
        load = new Loading(this);
        load->show();
    
        startWorkInAThread();
    
    }
    
    void Dockshow::Get_data(QTextDocument *doc)
    {
        this->setDocument(doc);
        load->hide();
    }
    
    
    

  • Qt Champions 2016

    hi
    It is still created in the context of the main thread.
    As far as I know all GUI 'widgets must be in main thread.

    Please see this example
    https://fabienpn.wordpress.com/2013/05/01/qt-thread-simple-and-stable-with-sources/

    and notice the:
    worker->moveToThread(thread);

    This makes it 100% detached from main thread.

    So the worker can get data from clipboard into qstringlist/QTextDocument and then send it to
    qplaintexteedit via signal.

    You are almost there but it seems your code is just a thread and not using a worker object but
    directly runs the code via PasteThread::run()



  • @mrjj Hello,

    the thread works fine but now I have another bug that's when I copy texts sometimes the bug software and it shows me this message

    "ASSERT:" isEmpty () "in file C: \ Qt \ QT5. 5.0 \ 5.5 \ msvc2013_64 \ include \ QtCore / qlist.h, line 316 "
    

    and when I google I didn't find someone who has this bug. I also see the line 316 qlist.h file and from what I understand it is a problem of iterator loop which one I do not know ?????


  • Qt Champions 2016

    @Aouache said:
    Hi Good work!
    seems to be this line
    inline T& first() { Q_ASSERT(!isEmpty()); return *begin(); }
    so It something internal maybe from QDocument or plainedit.

    Try to insert some check from data you read that it is not NULL or empty.
    Else try to look at data when it happens.
    Sadly its a Q_ASSERT so it most likely just kills the program.

    Also I have been meaning to ask you. Since you put it in Edit widget. Is
    it important to edit the data or is viewing simply enough ?



  • @mrjj yes edit the data and the users can change the mode read only for example. i try to find the bug in the data .


  • Qt Champions 2016

    @Aouache
    Ok. so you do need to edit also.
    Well the error suggest its something unusual so
    try to see if any hints with the data when it happens.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.