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. Error at using setTextCursor with Scroll.
Forum Update on Monday, May 27th 2025

Error at using setTextCursor with Scroll.

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.1k 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.
  • R Offline
    R Offline
    Robot
    wrote on last edited by
    #1

    Now I develop some Code editor, I have a big problem.
    I am using Qt4.
    The problem is occur at using Function of Highlighter current line with scrolling the QtextEdit.
    I used this highlighting code : http://www.qtcentre.org/threads/45634-QPlainTextEdit-highlight-selected-line

    and I made thread for Code editor and inside of thread use this function

    QTextCursor cursor(_pEditor->findBlockByLineNumber(line));
    _pEditor->setTextCursor(cursor);

    the error message is differ at some time.
    first thing is :
    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread 0xa975cb40]
    0xb6ec3fb1 in QTextLine::cursorTox(int*, QTextLine::Edge) const()
    ..........
    QPlainTextEdit::setTextCursor(QTextCursor const&)()
    .....

    second thing is :
    [xcb] Unknown request in queue while dequeuing
    [xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
    [xcb] Aborting, sorry about that.
    dequeue_pending_request: Assertion '!xcb_xlib_unknown_req_in_deq' failed.
    Aborted(core dumped)

    Error occur when change position of cursor with scrolling at gui.
    sometimes if i don't use scroll with short code, this problem occured.
    I don't know why this problem occur at this time.
    I want to get a hint for solve this problem.
    Please give me a you mention!
    Thank you

    jsulmJ 1 Reply Last reply
    0
    • R Robot

      Now I develop some Code editor, I have a big problem.
      I am using Qt4.
      The problem is occur at using Function of Highlighter current line with scrolling the QtextEdit.
      I used this highlighting code : http://www.qtcentre.org/threads/45634-QPlainTextEdit-highlight-selected-line

      and I made thread for Code editor and inside of thread use this function

      QTextCursor cursor(_pEditor->findBlockByLineNumber(line));
      _pEditor->setTextCursor(cursor);

      the error message is differ at some time.
      first thing is :
      Program received signal SIGSEGV, Segmentation fault.
      [Switching to Thread 0xa975cb40]
      0xb6ec3fb1 in QTextLine::cursorTox(int*, QTextLine::Edge) const()
      ..........
      QPlainTextEdit::setTextCursor(QTextCursor const&)()
      .....

      second thing is :
      [xcb] Unknown request in queue while dequeuing
      [xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
      [xcb] Aborting, sorry about that.
      dequeue_pending_request: Assertion '!xcb_xlib_unknown_req_in_deq' failed.
      Aborted(core dumped)

      Error occur when change position of cursor with scrolling at gui.
      sometimes if i don't use scroll with short code, this problem occured.
      I don't know why this problem occur at this time.
      I want to get a hint for solve this problem.
      Please give me a you mention!
      Thank you

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

      @Robot SIGSEGV is usually caused by a dangling/null pointer. Check this:

      QTextCursor cursor(_pEditor->findBlockByLineNumber(line));
      _pEditor->setTextCursor(cursor);
      

      is _pEditor null or dangling pointer?

      Do I understand you correctly that you have a second thread where you're handling your editor? If so then: DON'T DO THAT! All GUI related Qt classes (everything derived from QWidget) are not thread safe and should not be used outside of the main thread!

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

      R 1 Reply Last reply
      1
      • jsulmJ jsulm

        @Robot SIGSEGV is usually caused by a dangling/null pointer. Check this:

        QTextCursor cursor(_pEditor->findBlockByLineNumber(line));
        _pEditor->setTextCursor(cursor);
        

        is _pEditor null or dangling pointer?

        Do I understand you correctly that you have a second thread where you're handling your editor? If so then: DON'T DO THAT! All GUI related Qt classes (everything derived from QWidget) are not thread safe and should not be used outside of the main thread!

        R Offline
        R Offline
        Robot
        wrote on last edited by
        #3

        @jsulm
        Thank for reply it.
        _pEditor is not a dangling/null pointer.
        this pointer is class that inherited QplainTextedit.
        about your comment, I use second thread for doing coed that user made with _pEditor(QplainTextedit) and then use GUI classes for user.
        I want to give for user what is the line that currently doing at made _pEditor.
        so every execute of code, I change the current line with setTextCursor and Highlighter.
        but you said to me, I can't use GUI classes outside of main thread, How can I Highlight current line?!
        Thank you.

        jsulmJ 1 Reply Last reply
        0
        • R Robot

          @jsulm
          Thank for reply it.
          _pEditor is not a dangling/null pointer.
          this pointer is class that inherited QplainTextedit.
          about your comment, I use second thread for doing coed that user made with _pEditor(QplainTextedit) and then use GUI classes for user.
          I want to give for user what is the line that currently doing at made _pEditor.
          so every execute of code, I change the current line with setTextCursor and Highlighter.
          but you said to me, I can't use GUI classes outside of main thread, How can I Highlight current line?!
          Thank you.

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

          @Robot "_pEditor is not a dangling/null pointer" - how did you verify this? As I said SIGSEGV is usually caused by/null/dangling pointers - you should debug your app to find out what happens when it crashes.

          To your second question: your second thread should not modify the UI, instead it should emit a signal with needed parameters. In your GUI thread connect this signal to a slot where you then update your UI.

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

          1 Reply Last reply
          1

          • Login

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