Golevka / emacs-clang-complete-async

An emacs plugin to complete C and C++ code using libclang
360 stars 71 forks source link

The current version not work for Qt completions #76

Closed oracleyue closed 9 years ago

oracleyue commented 9 years ago

It works for std c/c++ library, boost, Eigen, etc., except QT, even for the simplest Qt code. It shows the information of the class, but it fails to show the members or member functions when . or ->, :: inserted. Not work even I have added all qt library pathes in ac-clang-flags. (Actually, for boost as an example, I don't need to add specific path /usr/include/boost into ac-clang-flags, it still works well.)

For instance, when I declear QApplication app(argc, argv); and cursor at the end character of QApplication, hit auto-complete trigger key, a list of complete shows as QApplication and QApplicationPrivate. It works well. However, when I wrote "app.", there is no completion list showing.

I think it is due to Qt keywords, like QT_GUI_EXPORT in the class declaration in header files. For example, class Q_GUI_EXPORT QApplication : public QCoreApplication, which is incorrent in C++ grammer if without processing macros of Q_GUI_EXPORT. Because in the included heder file "QApplication" (qapplication.h), there is no macro for QT_GUI_EXPORT. Please check it.

#include <qt4/QtGui/QApplication>
#include <qt4/QtGui/QLabel>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QLabel *label = new QLabel("Hello, Qt!");
    label->show();

    return app.exec();
}

Thank you very much!

oracleyue commented 9 years ago

Updates: I have found the QT_GUI_EXPORT is defined in QCore/qglobal.h. Then I included this header when I included <QApplication>. Now its completion for class members works well. Could you update it such that it automatically deals with such Qt keywords (macros)? Or, how can I set QCore/qglobal.h in .emacs for "emacs-clang-complete-async", such that I don't need to include QCore/qglobal.h every time in the source files when some keyboards used in class declarations?

And I also found that it only list the members and member functions defined for the class, without members and member functions inherited from the parent class. Probably it is difficult to handle such completions?

It works in the following case (adding QtCore/qglobal.h header ):

#include <qt4/QtCore/qglobal.h>
#include <qt4/QtGui/QApplication>
#include <qt4/QtGui/QLabel>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QLabel *label = new QLabel("Hello, Qt!");
    label->show();

    return app.exec();
}