Error at using setTextCursor with Scroll.

  • 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 :

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

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

    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

  • Lifetime Qt Champion

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

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

    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!

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

  • Lifetime Qt Champion

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

Log in to reply