I am setting CPP lexer to Scintilla but there is no colourisation. Tried in Windows and Ubuntu. Result is the same. What am I doing wrong?
Code reports that lexer is set. Tried setting text after setting lexer - not working too.
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
scintilla = new ScintillaEdit(this);
scintilla->setText("#include \"mainwindow.h\"\r\n\
\r\n\
#include <QApplication>\r\n\
\r\n\
int main(int argc, char *argv[])\r\n\
{\r\n\
QApplication a(argc, argv);\r\n\
MainWindow w;\r\n\
w.show();\r\n\
return a.exec();\r\n\
}\r\n\
\r\n\
");
#if _WIN32
typedef void *(__stdcall *CreateLexerFn)(const char *name);
typedef int (__stdcall *GetLexerCountFn)();
typedef void (__stdcall *GetLexerNameFn)(unsigned int index, char *name, int buflength);
#else
typedef void *(*CreateLexerFn)(const char *name);
typedef int (*GetLexerCountFn)();
typedef void (*GetLexerNameFn)(unsigned int index, char *name, int buflength);
#endif
QFunctionPointer fn = QLibrary::resolve("lexilla", "GetLexerCount");
int lexCount = ((GetLexerCountFn)fn)();
qDebug() << "Lexer count =" << lexCount;
if (lexCount > 0) {
fn = QLibrary::resolve("lexilla", "GetLexerName");
for (int i = 0; i < lexCount; i++) {
char name[100] = "";
((GetLexerNameFn)fn)(i, name, sizeof(name));
qDebug() << name;
}
fn = QLibrary::resolve("lexilla", "CreateLexer");
void *lexCpp = ((CreateLexerFn)fn)("cpp");
if (lexCpp != NULL) {
qDebug() << "cpp lexer created.";
sptr_t old_lexer = scintilla->lexer();
scintilla->setILexer((sptr_t)(void *)lexCpp);
sptr_t new_lexer = scintilla->lexer();
if (new_lexer == old_lexer) {
qDebug() << "Lexer is not set!";
}
else {
qDebug() << scintilla->lexerLanguage() << "lexer set!";
}
}
else {
qDebug() << "Lexer is NULL!";
}
}
setCentralWidget(scintilla);
scintilla->colourise(0, -1);
}