Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTextCursor causes segmentation fault
QtWS25 Last Chance

QTextCursor causes segmentation fault

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 5 Posters 3.0k Views
  • 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.
  • B Offline
    B Offline
    bs55
    wrote on last edited by bs55
    #1

    Hello everyone,

    I am developping a motion capture secquence recording program and I am trying to log the color messages in a QTextEdit (black = normal, orange = warning, red = critical).
    Unfortunatly the QTextCursor sometimes causes sefmentation fault.

    Here is my code:

    void MainWindow::logWarning(QString qs_Entry) {
        qWarning() << qs_Entry;
    
        try {
            QTextCursor qtc(qte_Log->textCursor());
    
            QTextCharFormat qtcf;
            qtcf.setForeground(QBrush(QColor("Orange")));
            qtc.setCharFormat(qtcf);
    
            qtc.insertText(qs_Entry + "\n");
        } catch (...) {
            qInfo() << "An unexpected error occured when logging a warning!";
        }
    }
    

    The try catch does not seems to catch the error.

    Did I do something wrong?
    If not, is there another way to display color messages in the QTextEdit without causing segmentation faults?

    Note: I don't know if it's relevant but my program is heavily multithreaded.

    JonBJ VRoninV 2 Replies Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Might be a silly question but are you sure that qte_Log is a valid pointer ?

      Otherwise, what does the stack trace tell you ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • B Offline
        B Offline
        bs55
        wrote on last edited by bs55
        #3

        @bs55 said in QTextCursor causes segmentation fault:

        qte_Log

        Yes, this pointer is valid.

        I forgot to specify that the code works but sometimes causes segmentation fault.

        Here is the debuger stack trace:
        1 ?? 0x7ffff3df5aac
        2 ?? 0x7ffff3dea28e
        3 ?? 0x7ffff3dea2e5
        4 QTextEngine::itemize() const 0x7ffff3dee69c
        5 QTextEngine::lineNumberForTextPosition(int) 0x7ffff3df0bed
        6 QTextLayout::lineForTextPosition(int) const 0x7ffff3df785c
        7 QTextCursorPrivate::setX() 0x7ffff3e47c4e
        8 QTextCursor::insertText(QString const&, QTextCharFormat const&) 0x7ffff3e49775
        9 QTextCursor::insertText(QString const&) 0x7ffff3e4a704
        10 MainWindow::log mainwindow.cpp 843 0x416edb
        11 MainWindow::captureProgressHandler mainwindow.cpp 600 0x414309
        12 QtPrivate::FunctorCall<QtPrivate::IndexesList<0, 1>, QtPrivate::List<int, double>, void, void (MainWindow:: *)(int, double)>::call qobjectdefs_impl.h 136 0x425cf0
        13 QtPrivate::FunctionPointer<void (MainWindow:: *)(int, double)>::call<QtPrivate::List<int, double>, void> qobjectdefs_impl.h 169 0x4251bf
        14 QtPrivate::QSlotObject<void (MainWindow:: *)(int, double), QtPrivate::List<int, double>, void>::impl qobject_impl.h 120 0x4243c6
        15 QMetaObject::activate(QObject *, int, int, void * *) 0x7ffff3756b96
        16 CaptureThread::signalCaptureProgress moc_capturethread.cpp 158 0x42d414
        17 CaptureThread::run capturethread.cpp 98 0x427dc8
        18 ?? 0x7ffff355d70a
        19 start_thread pthread_create.c 333 0x7ffff1b926ba
        20 clone clone.S 109 0x7ffff2c5841d
        ... <More>

        jsulmJ 1 Reply Last reply
        0
        • B bs55

          Hello everyone,

          I am developping a motion capture secquence recording program and I am trying to log the color messages in a QTextEdit (black = normal, orange = warning, red = critical).
          Unfortunatly the QTextCursor sometimes causes sefmentation fault.

          Here is my code:

          void MainWindow::logWarning(QString qs_Entry) {
              qWarning() << qs_Entry;
          
              try {
                  QTextCursor qtc(qte_Log->textCursor());
          
                  QTextCharFormat qtcf;
                  qtcf.setForeground(QBrush(QColor("Orange")));
                  qtc.setCharFormat(qtcf);
          
                  qtc.insertText(qs_Entry + "\n");
              } catch (...) {
                  qInfo() << "An unexpected error occured when logging a warning!";
              }
          }
          

          The try catch does not seems to catch the error.

          Did I do something wrong?
          If not, is there another way to display color messages in the QTextEdit without causing segmentation faults?

          Note: I don't know if it's relevant but my program is heavily multithreaded.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @bs55

          The try catch does not seems to catch the error.

          Just to be clear, try ... catch will only catch genuine, recoverable "errors". Once you have something like a Seg Fault, nothing will catch that.

          1 Reply Last reply
          0
          • B bs55

            @bs55 said in QTextCursor causes segmentation fault:

            qte_Log

            Yes, this pointer is valid.

            I forgot to specify that the code works but sometimes causes segmentation fault.

            Here is the debuger stack trace:
            1 ?? 0x7ffff3df5aac
            2 ?? 0x7ffff3dea28e
            3 ?? 0x7ffff3dea2e5
            4 QTextEngine::itemize() const 0x7ffff3dee69c
            5 QTextEngine::lineNumberForTextPosition(int) 0x7ffff3df0bed
            6 QTextLayout::lineForTextPosition(int) const 0x7ffff3df785c
            7 QTextCursorPrivate::setX() 0x7ffff3e47c4e
            8 QTextCursor::insertText(QString const&, QTextCharFormat const&) 0x7ffff3e49775
            9 QTextCursor::insertText(QString const&) 0x7ffff3e4a704
            10 MainWindow::log mainwindow.cpp 843 0x416edb
            11 MainWindow::captureProgressHandler mainwindow.cpp 600 0x414309
            12 QtPrivate::FunctorCall<QtPrivate::IndexesList<0, 1>, QtPrivate::List<int, double>, void, void (MainWindow:: *)(int, double)>::call qobjectdefs_impl.h 136 0x425cf0
            13 QtPrivate::FunctionPointer<void (MainWindow:: *)(int, double)>::call<QtPrivate::List<int, double>, void> qobjectdefs_impl.h 169 0x4251bf
            14 QtPrivate::QSlotObject<void (MainWindow:: *)(int, double), QtPrivate::List<int, double>, void>::impl qobject_impl.h 120 0x4243c6
            15 QMetaObject::activate(QObject *, int, int, void * *) 0x7ffff3756b96
            16 CaptureThread::signalCaptureProgress moc_capturethread.cpp 158 0x42d414
            17 CaptureThread::run capturethread.cpp 98 0x427dc8
            18 ?? 0x7ffff355d70a
            19 start_thread pthread_create.c 333 0x7ffff1b926ba
            20 clone clone.S 109 0x7ffff2c5841d
            ... <More>

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @bs55 To add to @JonB : Qt itself does not use (throw) exceptions.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            JonBJ 1 Reply Last reply
            0
            • B bs55

              Hello everyone,

              I am developping a motion capture secquence recording program and I am trying to log the color messages in a QTextEdit (black = normal, orange = warning, red = critical).
              Unfortunatly the QTextCursor sometimes causes sefmentation fault.

              Here is my code:

              void MainWindow::logWarning(QString qs_Entry) {
                  qWarning() << qs_Entry;
              
                  try {
                      QTextCursor qtc(qte_Log->textCursor());
              
                      QTextCharFormat qtcf;
                      qtcf.setForeground(QBrush(QColor("Orange")));
                      qtc.setCharFormat(qtcf);
              
                      qtc.insertText(qs_Entry + "\n");
                  } catch (...) {
                      qInfo() << "An unexpected error occured when logging a warning!";
                  }
              }
              

              The try catch does not seems to catch the error.

              Did I do something wrong?
              If not, is there another way to display color messages in the QTextEdit without causing segmentation faults?

              Note: I don't know if it's relevant but my program is heavily multithreaded.

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              @bs55 said in QTextCursor causes segmentation fault:

              Note: I don't know if it's relevant but my program is heavily multithreaded.

              Is MainWindow::logWarning called directly from a secondary thread?

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              B 1 Reply Last reply
              0
              • jsulmJ jsulm

                @bs55 To add to @JonB : Qt itself does not use (throw) exceptions.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @jsulm said in QTextCursor causes segmentation fault:

                @bs55 To add to @JonB : Qt itself does not use (throw) exceptions.

                OK. But if the underlying OS/windowing system does throw exceptions, would Qt catch them guaranteed or would they pass through to the calling code?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Qt by default is build without exception support disabled.

                  For the rest see the Exception Safety chapter in Qt's documentation.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  2
                  • VRoninV VRonin

                    @bs55 said in QTextCursor causes segmentation fault:

                    Note: I don't know if it's relevant but my program is heavily multithreaded.

                    Is MainWindow::logWarning called directly from a secondary thread?

                    B Offline
                    B Offline
                    bs55
                    wrote on last edited by
                    #9

                    @VRonin No the threads emit signals connected to a slot that uses the logWarning function.

                    jsulmJ VRoninV 2 Replies Last reply
                    0
                    • B bs55

                      @VRonin No the threads emit signals connected to a slot that uses the logWarning function.

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @bs55 Did you use QueuedConnection in connect?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      1
                      • B bs55

                        @VRonin No the threads emit signals connected to a slot that uses the logWarning function.

                        VRoninV Offline
                        VRoninV Offline
                        VRonin
                        wrote on last edited by
                        #11

                        @bs55 said in QTextCursor causes segmentation fault:

                        No the threads emit signals connected to a slot that uses the logWarning function

                        Looks like they are connected with Qt::DirectConnection though which is equal to calling the slot from another thread

                        11 MainWindow::captureProgressHandler mainwindow.cpp 600 0x414309
                        [...]
                        16 CaptureThread::signalCaptureProgress moc_capturethread.cpp 158 0x42d414
                        17 CaptureThread::run capturethread.cpp 98 0x427dc8
                        

                        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                        ~Napoleon Bonaparte

                        On a crusade to banish setIndexWidget() from the holy land of Qt

                        1 Reply Last reply
                        3

                        • Login

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