[SOLVED] qtcreator ui-> autocompletion doesn't work if I split some funcs out of the original .cpp



  • Hello.

    This is a complete newbie question so just bear with me :P

    I've been working with qtcreator for many months and autocompletion has always worked fine. Now, the critter has gotten big enough, and I am taking some time to organise a bit my code. In the process I took some related methods and put them into a separate .cpp file, #including in turn that new .cpp file into the old (bigger) one. So far, it compiles fine as expected.

    But, when I went back to qtcreator to continue coding, I discovered that completion doesn't work any more with the ui class. It seems to work still for all my custom classes though.

    I am not using any #include in that split cpp file. From the C++ point of view I don't think it's necessary, but qtcreator doesn't seem to think the same. If I #include back the main cpp file into the new one, then completion works, but, of course, compilation fails due to duplicate declarations and all that.

    So, what's the proper way to make completion work when you split one big cpp file into several ones?

    Thank you! :)



  • you should avoid to includ cpp files. but you can include the header file in both cpp files. so you have completition in both and it compiles correctly.

    Header:
    @// MyClass.h
    class MyClass {
    public:
    void method1();
    void method2();
    };@

    Source file 1
    @// MyClass1.cpp
    #include "MyClass.h"

    MyClass::method1() {
    // code
    }@

    Source file 2
    @//MyClass2.cpp
    #include "MyClass.h"
    MyClass::method2() {
    // code
    }@



  • Thanks but I also tried that. It works for everything I have written myself, but it doesn't seem to catch ui-> completion. It compiles and all that if I write it myself, so ui is in the scope, but autocompletion for that class just doesn't work on the splitted cpp file.

    It has always worked (and still works) without problems in the original cpp file... Maybe there's some setting in qtcreator that controls that?



  • where is the include of the "ui_XYZ.h" file? If it is in the first .cpp file, just include it in the second one or move the include to the header file.



  • Thanks. That was it. :)

    Including it to the .h file worked.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.