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.app/Contents/MacOS/Text crashed.
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.
I'm currently using:
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!!
Oh! I have figured it out that I must use the pointer references for the QsciAPIs. If I've use it, I won't crash.
QsciAPIs* api;
api = new QsciAPIs(this);