Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QplaintextEdit Paste problem of memory
Qt 6.11 is out! See what's new in the release blog

QplaintextEdit Paste problem of memory

Scheduled Pinned Locked Moved Unsolved General and Desktop
20 Posts 2 Posters 10.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mrjjM mrjj

    @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.

    ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #5

    @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.

    mrjjM 1 Reply Last reply
    0
    • ? A Former User

      @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.

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #6

      @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?

      ? 1 Reply Last reply
      0
      • mrjjM mrjj

        @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?

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #7

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

        mrjjM 1 Reply Last reply
        0
        • ? A Former User

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

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #8

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

          ? 1 Reply Last reply
          0
          • mrjjM mrjj

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

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #9

            @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.

            mrjjM 1 Reply Last reply
            0
            • ? A Former User

              @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.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #10

              @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.

              ? 1 Reply Last reply
              0
              • mrjjM mrjj

                @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.

                ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #11

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

                mrjjM 1 Reply Last reply
                0
                • ? A Former User

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

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #12

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

                  ? 1 Reply Last reply
                  0
                  • mrjjM mrjj

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

                    ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #13

                    @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 ?

                    1 Reply Last reply
                    0
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #14

                      @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?

                      ? 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @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?

                        ? Offline
                        ? Offline
                        A Former User
                        wrote on last edited by
                        #15

                        @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();
                        }
                        
                        
                        
                        1 Reply Last reply
                        1
                        • mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by mrjj
                          #16

                          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()

                          ? 1 Reply Last reply
                          0
                          • mrjjM mrjj

                            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()

                            ? Offline
                            ? Offline
                            A Former User
                            wrote on last edited by
                            #17

                            @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 ?????

                            mrjjM 1 Reply Last reply
                            0
                            • ? A Former User

                              @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 ?????

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by mrjj
                              #18

                              @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 ?

                              ? 1 Reply Last reply
                              0
                              • mrjjM mrjj

                                @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 ?

                                ? Offline
                                ? Offline
                                A Former User
                                wrote on last edited by
                                #19

                                @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 .

                                mrjjM 1 Reply Last reply
                                0
                                • ? A Former User

                                  @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 .

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #20

                                  @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.

                                  1 Reply Last reply
                                  0

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt
                                  • Unsolved