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. C++ - Application crashes at QsciScintilla auto complete
Qt 6.11 is out! See what's new in the release blog

C++ - Application crashes at QsciScintilla auto complete

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 728 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.
  • J Offline
    J Offline
    JackMyson
    wrote on last edited by
    #1

    I have installed the QScintilla 2 into my MacBook, and I am currently using C++ and the Qt framework to develop a QScintilla-related text editor. Briefly introduced that I have a main window class, an editor class, and some lexers.

    My problem is, I discovered that when I type into the application (that means typing into the editor, triggered QKeyEvent*), the application will crash without a reason.

    I am using Qt Creator as the IDE now, so I may show you the application output message:

    19:56:13: Starting /Users/jason/Desktop/Projects/Text/bin/Text.app/Contents/MacOS/Text...
    19:56:23: /Users/jason/Desktop/Projects/Text/bin/Text
    

    When trying the LLDB for the application using Qt Creator's built-in debugger, the crash message shows below:

    20:01:47: Debugging /Users/jason/Desktop/Projects/Text/bin/Text.app/Contents/MacOS/Text ...
    
    got fallback qt version 0x60402
    2023-03-10 20:02:02.734376+0800 Text[5183:2288553] SecTaskLoadEntitlements failed error=22 cs_flags=20, pid=5183
    2023-03-10 20:02:02.734572+0800 Text[5183:2288553] SecTaskCopyDebugDescription: Text[5183]/0#-1 LF=0
    2023-03-10 20:02:05.190416+0800 Text[5183:2288553] SecTaskLoadEntitlements failed error=22 cs_flags=20, pid=5183
    2023-03-10 20:02:05.190551+0800 Text[5183:2288553] SecTaskCopyDebugDescription: Text[5183]/0#-1 LF=0
    20:03:08: Debugging of /Users/jason/Desktop/Projects/Text/bin/Text.app/Contents/MacOS/Text has finished.
    

    lldb for the application

    I'm currently using:

    • macOS version 11.7.3 Big Sur on Intel MacBook Air mid-2013
    • Qt 6.4.2 for macOS
    • C++ 17
    • XCode 13

    Here's shown the MRE:

    editor.cpp

    #include "editor.h"
    #include "lexerpython3.h"
    
    Editor::Editor(QWidget* parent) : QsciScintilla(parent)
    {
        LexerPython3 *m_lexerPython3 = new LexerPython3(m_font);
        setCallTipsPosition(CallTipsPosition::CallTipsBelowText);
        setCallTipsVisible(-1);
        setAutoIndent(true);
        setAutoCompletionSource(QsciScintilla::AutoCompletionSource::AcsAll);
        setAutoCompletionThreshold(1);
        setAutoCompletionCaseSensitivity(false);
        setAutoCompletionReplaceWord(true);
    }
    
    

    lexerpython3.h

    #ifndef LEXERPYTHON3_H
    #define LEXERPYTHON3_H
    
    #include <QObject>
    #include <QFont>
    
    #include <Qsci/qscilexerpython.h>
    
    class LexerPython3 : public QsciLexerPython
    {
        Q_OBJECT
    
    public:
    
        LexerPython3(QFont font, QObject* object = nullptr);
    
        const char *keywords(int set) const;
    
    private:
    
        QFont m_font;
    
        const char* key = "and as assert break class continue def del elif else except exec "
                          "finally for from global if import in is lambda None not or pass "
                          "print raise return try while with yield";
    
        QString m_calltips;
    };
    
    #endif // LEXERPYTHON3_H
    
    

    lexerpython3.cpp

    #include "lexerpython3.h"
    
    #include <QColor>
    #include <Qsci/qsciapis.h>
    
    LexerPython3::LexerPython3(QFont font, QObject* parent)
        : QsciLexerPython(parent)
    {
        // Defining variables...
        m_font = font;
    
        m_calltips = "ArithmeticError() "
                     "AssertionError() "
                     ...
                     ...
                "__build_class__(func, name, a, *bases, [metaclass], **kwds) "
                "__import__(name, globals=None, locals=None, fromlist=(), level=0) "
                "all(iterable, /) "
                "anext(aiterator[, default]) "
                "any(iterable, /)";
    
        setFoldCompact(false);
        setFoldQuotes(true);
        setFoldComments(true);
    
        setIndentationWarning(QsciLexerPython::IndentationWarning::Inconsistent);
        setV2UnicodeAllowed(false);
    
        QsciAPIs api(this);
    
        for (const QString &item1 : QString(key).split(" "))
        {
            api.add(item1);
        }
    
        for (QString item2 : m_calltips.split(" "))
        {
            api.add(item2);
        }
    
        api.prepare();
    }
    
    const char* LexerPython3::keywords(int set) const
    {
        if (set != 1)
    
            return 0;
    
        return key;
    }
    
    

    Any help or comments will be appreciated! Thanks!!

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JackMyson
      wrote on last edited by
      #4

      Oh... I figure it out. I think it's the problem of not using the pointer references.

      // QsciAPIs api(this); // crashes!
      QsciAPIs* api;
      api = new QsciAPIs(this);
      // Now it won't crash
      
      for (const QString &s : /**/)
      {
          ///...
      ///...
      ///...
      
      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        I haven't used QScintilla for a very long time but aren't you using QsciAPIs the wrong way ?

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

        J 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          I haven't used QScintilla for a very long time but aren't you using QsciAPIs the wrong way ?

          J Offline
          J Offline
          JackMyson
          wrote on last edited by
          #3

          @SGaist

          Um... I don't really know. However, I've been using Python language in this way and I have translated it into C++ manually and directly. In Python, all the functions and classes works well and no exceptions are raised...

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JackMyson
            wrote on last edited by
            #4

            Oh... I figure it out. I think it's the problem of not using the pointer references.

            // QsciAPIs api(this); // crashes!
            QsciAPIs* api;
            api = new QsciAPIs(this);
            // Now it won't crash
            
            for (const QString &s : /**/)
            {
                ///...
            ///...
            ///...
            
            1 Reply Last reply
            0
            • J JackMyson has marked this topic as solved on

            • Login

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