Qt 使用QScintilla 编辑lua 脚本

需求:

利用QScintilla 编辑lua 脚本

步骤:

1,下载 QScintilla Riverbank Computing | Download

2, 打开 src/qscintilla.pro 文件 编译出 dll库

3,工程中引入这个库

注意debug 模式 必须加载debug 版本编译的库,不然回提示 "QWidget: Must construct a QApplication before a QWidget"

4,使用

复制代码
#include <QApplication>

#include <QMainWindow>
#include <QVBoxLayout>
#include <qsciscintilla.h>
#include <qscilexerlua.h>
#include <qsciapis.h>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    // 创建窗口和布局
    QMainWindow  window;

    // 创建编辑器控件
    QsciScintilla editor(&window);
    window.setCentralWidget(&editor);
    editor.setMarginWidth(0, 40);
    editor.setIndentationGuides(true);
    editor.setTabWidth(4);
    editor.setUtf8(true);

    QsciLexerLua *textLexer = new QsciLexerLua;
    editor.setLexer(textLexer);

    //设置编码为UTF-8
    QsciAPIs apis(textLexer);
    apis.add(QString("and"));
    apis.add(QString("break"));
    apis.add(QString("do"));
    apis.add(QString("else"));
    apis.add(QString("elseif"));
    apis.add(QString("end"));
    apis.add(QString("false"));
    apis.add(QString("for"));
    apis.add(QString("function"));
    apis.add(QString("if"));
    apis.add(QString("in"));
    apis.add(QString("local"));
    apis.add(QString("nil"));
    apis.add(QString("not"));
    apis.add(QString("or"));
    apis.add(QString("repeat"));
    apis.add(QString("return"));
    apis.add(QString("then"));
    apis.add(QString("true"));
    apis.add(QString("until"));
    apis.add(QString("while"));
    apis.prepare();

    editor.setAutoCompletionSource(QsciScintilla::AcsAll);
    editor.setAutoCompletionCaseSensitivity(true);
    editor.setAutoCompletionThreshold(1);
    editor.SendScintilla(QsciScintilla::SCI_SETCODEPAGE,QsciScintilla::SC_CP_UTF8);
    editor.setCaretLineVisible(true);
    editor.setFolding(QsciScintilla::BoxedFoldStyle);

    // 显示窗口
    window.show();

    return app.exec();
}

5,效果

相关推荐
meiying883830 分钟前
快递单号批量查询Python脚本:从手动到自动化的完整实现
开发语言·python·自动化
@大迁世界1 小时前
告别 Go,拥抱 Rust
开发语言·golang·rust
SEO_juper1 小时前
Node.js 重定向链检测工具:301 跳了几跳、有没有成环,一次看清
xml·开发语言·python·node.js·json·bash
学逆向的1 小时前
C 指针常量与常量指针
c语言·开发语言·网络安全
低调滴开发2 小时前
3 行代码写崩一个函数?切片才是 Rust 字符串处理的正确姿势
开发语言·后端·rust
CodeYp20192 小时前
第15讲:二叉搜索树
开发语言·c++·二叉搜索树
猫猫.1532 小时前
HashTable、HashMap、ConcurrentHashMap 核心区别总结
java·开发语言·java-ee
乌暮4 小时前
综合案例:宠物电商系统
java·开发语言·spring·mvc·restful·1024程序员节
大文说跨境4 小时前
亚马逊多店铺的图片素材怎么批量去重:EXIF 与哈希的处理流程
开发语言·php
大风起兮云飞扬丶5 小时前
Java——枚举
java·开发语言