Results 1 to 2 of 2

Thread: App crashes on error ASSERT: "n" in file ..\..\include\QtGui/private/../../../src/gui

  1. #1

    Default App crashes on error ASSERT: "n" in file ..\..\include\QtGui/private/../../../src/gui

    Hi,
    i'm trying to do simple formating function with QTextCursor in QPlainTextEdit, but still don't understand why my example app crashes with error:
    Qt Code:
    1. Starting C:\Qt\Projects\untitled-build-desktop\debug\untitled.exe...
    2. ASSERT: "n" in file ..\..\include\QtGui/private/../../../src/gui/text/qfragmentmap_p.h, line 291
    3. C:\Qt\Projects\untitled-build-desktop\debug\untitled.exe exited with code 3
    To copy to clipboard, switch view to plain text mode 

    I have this simple code:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4. this->edit=new QPlainTextEdit(this);
    5. this->setCentralWidget(this->edit);
    6. connect(edit->document(),SIGNAL(contentsChange(int,int,int)),this,SLOT(contentsChange(int,int,int)));
    7. }
    8.  
    9. void MainWindow::contentsChange(int position,int charsRemoved,int charsAdded) {
    10. if (this->edit->toPlainText().length()>10) {
    11. QTextCursor *curA=new QTextCursor(this->edit->document()->findBlock(0));
    12. QTextCharFormat charFormat;
    13. charFormat.setFontItalic(true);
    14. curA->setPosition(0,QTextCursor::MoveAnchor);
    15. curA->setPosition(4,QTextCursor::KeepAnchor);
    16. curA->beginEditBlock();
    17. if (curA->hasSelection()) {
    18. curA->mergeCharFormat(charFormat);
    19. curA->clearSelection();
    20. }
    21. curA->endEditBlock();
    22. delete curA;
    23. }
    24. }
    To copy to clipboard, switch view to plain text mode 

    I'm trying to create simple function which formats specified number of characters from specified position (something like setFormat(int position,int length)) with QTextCursor, but my function is crashing because of mentioned error, so i have prepared simple example to show you way how i'm trying to do it.
    Attached Files Attached Files

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: App crashes on error ASSERT: "n" in file ..\..\include\QtGui/private/../../../src

    You are trying to merge italic formatting into a QPlainTextEditor. You need to use QTextEditor for that.

    In your contentsChange() method you allocate curA on the heap and delete it at the end. This heap allocation gives you no benefit over a simple local variable stack allocation, but exposes you memory leaks in the event of abnormal program exit.

Similar Threads

  1. Replies: 32
    Last Post: 26th August 2012, 00:10
  2. Replies: 9
    Last Post: 20th May 2010, 10:55
  3. Replies: 2
    Last Post: 6th October 2009, 02:09
  4. "Treat wchar_t as Built-in Type" to "yes" link error
    By sungaoyong in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2008, 12:45
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 16:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.