Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Auto-complete doens't work for header files.

Auto-complete doens't work for header files.

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 3 Posters 4.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NeoFahrenheit
    wrote on last edited by NeoFahrenheit
    #1

    Hi guys,
    Sorry to bother, but I still have this problem.

    I'm building a 2048 game, as to keep thinks organized, I did make some header files. The thing is the auto-complete doens't work on header files. I've included these header files on 'main.c', if that helps. I discovery that the auto-complete work if I put "#include "main.c"" on those header files, but I recieve some compiler erros if I do.

    The auto-complete does work for the functions I create, but not for library functions, like printf or scanf.

    Solutions?
    This is my .pro file:
    alt text

    joeQJ 1 Reply Last reply
    0
    • N NeoFahrenheit

      Hi guys,
      Sorry to bother, but I still have this problem.

      I'm building a 2048 game, as to keep thinks organized, I did make some header files. The thing is the auto-complete doens't work on header files. I've included these header files on 'main.c', if that helps. I discovery that the auto-complete work if I put "#include "main.c"" on those header files, but I recieve some compiler erros if I do.

      The auto-complete does work for the functions I create, but not for library functions, like printf or scanf.

      Solutions?
      This is my .pro file:
      alt text

      joeQJ Offline
      joeQJ Offline
      joeQ
      wrote on last edited by
      #2

      @NeoFahrenheit hi,friend,welcome.

      First to work out the compiler error.

      What's compiler error ? can you show the message about compiler error?

      From your *.pro file, you used the LIBS += **, do you have these libraries?

      I am confused, why did you to #include "main.c" file? show me your main.c file, just head some lines in file is OK.

      Just do it!

      N 1 Reply Last reply
      1
      • joeQJ joeQ

        @NeoFahrenheit hi,friend,welcome.

        First to work out the compiler error.

        What's compiler error ? can you show the message about compiler error?

        From your *.pro file, you used the LIBS += **, do you have these libraries?

        I am confused, why did you to #include "main.c" file? show me your main.c file, just head some lines in file is OK.

        N Offline
        N Offline
        NeoFahrenheit
        wrote on last edited by NeoFahrenheit
        #3

        @joeQ If I include "main.c" in a header file, I got "redefinition of main".
        Yes, I have these libraries. The code is working right now.

        The top first is a header file called menus.h. I've included the source file, "main.c". That way I get auto-complete, but that compile error.

        The botton one is my source file, main.c.

        alt text

        joeQJ 1 Reply Last reply
        0
        • N NeoFahrenheit

          @joeQ If I include "main.c" in a header file, I got "redefinition of main".
          Yes, I have these libraries. The code is working right now.

          The top first is a header file called menus.h. I've included the source file, "main.c". That way I get auto-complete, but that compile error.

          The botton one is my source file, main.c.

          alt text

          joeQJ Offline
          joeQJ Offline
          joeQ
          wrote on last edited by joeQ
          #4

          @NeoFahrenheit said in Auto-complete doens't work for header files.:

          The top first is a header file called menus.h. I've included the source file, "main.c".

          You include main.c in menus.h file., remove this line frome menus.h file.

          you make include loop.

          in menus.h file

          #include "colors.h"
          #include "classicmode.h"
          //#include "main.c" ///< remove this line, Note: not to include `*.c *cpp` in head file. it will make include loop.
          ...
          

          in main.c file

          #include <ncurses.h>
          #include <menu.h>
          #include <stdlib.h>
          
          #include "windows.h"
          #include "colors.h"
          #include "menus.h" ///< at here, you include menus.h, means load menus.h file content, "colors.h" and "classicmode.h", if you include main.c in menus.h, you will reload these head files. not to include `*.c *cpp` in head file. it will make include loop.
          ...
          

          Just do it!

          N 1 Reply Last reply
          1
          • joeQJ joeQ

            @NeoFahrenheit said in Auto-complete doens't work for header files.:

            The top first is a header file called menus.h. I've included the source file, "main.c".

            You include main.c in menus.h file., remove this line frome menus.h file.

            you make include loop.

            in menus.h file

            #include "colors.h"
            #include "classicmode.h"
            //#include "main.c" ///< remove this line, Note: not to include `*.c *cpp` in head file. it will make include loop.
            ...
            

            in main.c file

            #include <ncurses.h>
            #include <menu.h>
            #include <stdlib.h>
            
            #include "windows.h"
            #include "colors.h"
            #include "menus.h" ///< at here, you include menus.h, means load menus.h file content, "colors.h" and "classicmode.h", if you include main.c in menus.h, you will reload these head files. not to include `*.c *cpp` in head file. it will make include loop.
            ...
            
            N Offline
            N Offline
            NeoFahrenheit
            wrote on last edited by NeoFahrenheit
            #5

            @joeQ Yes, this is exacly what I do when I want to make the code to run. But I don't get auto-complete this way.

            When I really need auto-complete, I include "main.c" in the header file I'm working on and, before running it, I remove that line.
            PS: I can try to make a video, if that helps.

            joeQJ 1 Reply Last reply
            0
            • N NeoFahrenheit

              @joeQ Yes, this is exacly what I do when I want to make the code to run. But I don't get auto-complete this way.

              When I really need auto-complete, I include "main.c" in the header file I'm working on and, before running it, I remove that line.
              PS: I can try to make a video, if that helps.

              joeQJ Offline
              joeQJ Offline
              joeQ
              wrote on last edited by joeQ
              #6

              @NeoFahrenheit

              do you want to auto-complete code in Qt IDE ?
              OK, i wan to see some gif images or some videos.

              Just do it!

              N 1 Reply Last reply
              0
              • joeQJ joeQ

                @NeoFahrenheit

                do you want to auto-complete code in Qt IDE ?
                OK, i wan to see some gif images or some videos.

                N Offline
                N Offline
                NeoFahrenheit
                wrote on last edited by NeoFahrenheit
                #7

                @joeQ Here's the video: https://youtu.be/L2B4uMwB-Rg
                PS: Maybe wait a little bit while YouTube processes higher quality.

                joeQJ 1 Reply Last reply
                0
                • N NeoFahrenheit

                  @joeQ Here's the video: https://youtu.be/L2B4uMwB-Rg
                  PS: Maybe wait a little bit while YouTube processes higher quality.

                  joeQJ Offline
                  joeQJ Offline
                  joeQ
                  wrote on last edited by joeQ
                  #8

                  @NeoFahrenheit

                  Sorry friend. I can not access this video site.

                  First, did you program compiler OK after remove that line?

                  did you program run OK ?

                  Just do it!

                  N 1 Reply Last reply
                  0
                  • joeQJ joeQ

                    @NeoFahrenheit

                    Sorry friend. I can not access this video site.

                    First, did you program compiler OK after remove that line?

                    did you program run OK ?

                    N Offline
                    N Offline
                    NeoFahrenheit
                    wrote on last edited by
                    #9

                    @joeQ Yes, if I remove the "main.c" in the header file, the program compile just fine.
                    Is there other to send you the video, then?

                    joeQJ 1 Reply Last reply
                    0
                    • N NeoFahrenheit

                      @joeQ Yes, if I remove the "main.c" in the header file, the program compile just fine.
                      Is there other to send you the video, then?

                      joeQJ Offline
                      joeQJ Offline
                      joeQ
                      wrote on last edited by
                      #10

                      @NeoFahrenheit

                      What is the problem now?
                      did your Qt IDE not to auto-complete code when you write code ?

                      if yes, did you to set the Qt IDE Options in Qt IDE Tools menu?

                      Just do it!

                      N 1 Reply Last reply
                      0
                      • joeQJ joeQ

                        @NeoFahrenheit

                        What is the problem now?
                        did your Qt IDE not to auto-complete code when you write code ?

                        if yes, did you to set the Qt IDE Options in Qt IDE Tools menu?

                        N Offline
                        N Offline
                        NeoFahrenheit
                        wrote on last edited by NeoFahrenheit
                        #11

                        @joeQ That's right. My problem is the Qt doens't sugest auto-complete when I'm writing code.
                        I did not mess with IDE Tools or options, tough I show some windows of it in that video.

                        If you could only watch the video, you'll understand better. I can upload it somewhere else. It is only 4.7MB.

                        joeQJ 1 Reply Last reply
                        0
                        • N NeoFahrenheit

                          @joeQ That's right. My problem is the Qt doens't sugest auto-complete when I'm writing code.
                          I did not mess with IDE Tools or options, tough I show some windows of it in that video.

                          If you could only watch the video, you'll understand better. I can upload it somewhere else. It is only 4.7MB.

                          joeQJ Offline
                          joeQJ Offline
                          joeQ
                          wrote on last edited by
                          #12

                          @NeoFahrenheit

                          I give my mail address to you from chats.

                          Just do it!

                          N 1 Reply Last reply
                          0
                          • joeQJ joeQ

                            @NeoFahrenheit

                            I give my mail address to you from chats.

                            N Offline
                            N Offline
                            NeoFahrenheit
                            wrote on last edited by
                            #13

                            @joeQ Ok! :)

                            joeQJ 1 Reply Last reply
                            0
                            • N NeoFahrenheit

                              @joeQ Ok! :)

                              joeQJ Offline
                              joeQJ Offline
                              joeQ
                              wrote on last edited by joeQ
                              #14

                              @NeoFahrenheit

                              as we know, all the variables and function are declared in head file(*.h). if you want to use them, you should include them at head *.cpp *.c *.h file.

                              if you want use other variable and function in menus.h file. you should include corresponding head file.

                              in menus.h

                              #include <stdio.h> ///< if you want to use `print..` function, you should include this head file
                              #include <ncurses.h>
                              #include <menu.h>
                              #include <stdlib.h> 
                              
                              #include "classicmode.h"
                              #include "windows.h"
                              #include "colors.h" ///< if you want to use some color variables and function, you should include this head file
                              

                              Just do it!

                              N 1 Reply Last reply
                              1
                              • joeQJ joeQ

                                @NeoFahrenheit

                                as we know, all the variables and function are declared in head file(*.h). if you want to use them, you should include them at head *.cpp *.c *.h file.

                                if you want use other variable and function in menus.h file. you should include corresponding head file.

                                in menus.h

                                #include <stdio.h> ///< if you want to use `print..` function, you should include this head file
                                #include <ncurses.h>
                                #include <menu.h>
                                #include <stdlib.h> 
                                
                                #include "classicmode.h"
                                #include "windows.h"
                                #include "colors.h" ///< if you want to use some color variables and function, you should include this head file
                                
                                N Offline
                                N Offline
                                NeoFahrenheit
                                wrote on last edited by NeoFahrenheit
                                #15

                                @joeQ Hmm, this way works. But, as far I can remenber (I could be wrong), in others IDE's I don't have to do this (like MS Visual Studio).
                                My headers file already "see" my include libraries from the main.c.

                                Well, if there is no other way, guess I'll be redeclaring my libraries to all my header files. It's nothing hard to do. :)
                                Just copy some lines. :)

                                Thanks for your help.

                                1 Reply Last reply
                                1
                                • aha_1980A Offline
                                  aha_1980A Offline
                                  aha_1980
                                  Lifetime Qt Champion
                                  wrote on last edited by aha_1980
                                  #16

                                  Hi @NeoFahrenheit

                                  My headers file already "see" my include libraries from the main.c

                                  No, Creator is right here.

                                  You have to understand how the include mechanism works. If you have two files main.h and main.c with following content:

                                  // main.h
                                  #ifndef MAIN_H
                                  #define MAIN_H
                                  
                                  #define FOO 42
                                  extern int i;
                                  
                                  #endif
                                  
                                  // main.c
                                  #include "main.h"
                                  
                                  int main()
                                  {
                                  }
                                  

                                  then the C preprocessor does the following replacement in main.c (and this is what the C compiler finally sees, because the C compiler does not even know about headers):

                                  // main.c
                                  #define FOO 42
                                  extern int i;
                                  
                                  int main()
                                  {
                                  }
                                  

                                  So if you include multiple files in the C file, following included headers "see" the symbols of previously included ones. But as soon as you change the include order, or you include the header file in another C file, things may no longer work.

                                  So it is very recommended, to include all needed headers also in your header file. Thje C preprocessor assures that each needed header is only included once by means of the #ifndef FOO_H / #define FOO_H / #endif header guards.

                                  The best way to verify your header is set up correct, is to include your main.h as first include in main.c, so the compiler will already complain about missing headers. I always use the following order and have an empty line between the blocks:

                                  // xyz.c
                                  #include "xyz.h"
                                  
                                  #include "otherprojectfiles.h" // other headers from your project
                                  
                                  #include <usedlibrary.h> // 3rdparty libraries used in your project
                                  
                                  #include <systemlibrary.h> // e.g. Linux or Windows headers
                                  
                                  #include <compilerlibrary.h> // Compiler headers, e.g. stdio.h
                                  

                                  Qt has to stay free or it will die.

                                  1 Reply Last reply
                                  0

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved