如何在qt中实现代码完成[关闭]

问题描述 投票:5回答:3

我正在使用qt(在c ++上)编写一个ide,我需要为它添加自动完成功能

所以我想知道:

怎么做(我使用qtPlainTextEdit)?

我应该使用什么数据结构?

c++ qt ide autocomplete
3个回答
8
投票

我想你应该看看这个: http://qt-project.org/doc/qt-4.8/tools-customcompleter.html

我用这个例子来理解CodeCompletion,我觉得很好:)

[编辑] Qt有一个自己的类叫做QCompleter:http://qt-project.org/doc/qt-4.8/qcompleter.html


3
投票

我还需要在Qt中编写代码完成者,Tobias提供的第一个链接是要查看的文档。它全面而清晰,为我工作。我相信你会为你工作。

如果你需要在lineEdit中使用代码完成器,那么它非常简单(来自QCompleter文档):

QStringList wordList;
wordList << "one" << "two" << "three" << "four" << "five";
QLineEdit *lineEdit = new QLineEdit(this);

QCompleter *completer = new QCompleter(wordList, this);
lineEdit->setCompleter(completer);

但是,QPlainTextEdit或QTextEdit没有内置的setCompleter()成员函数,因此您必须遵循custom code completer教程。


1
投票

这是一个很大的复杂功能。我会看看它是如何在the Qt Creator完成的。

© www.soinside.com 2019 - 2024. All rights reserved.