Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Fake error with structure
Forum Updated to NodeBB v4.3 + New Features

Fake error with structure

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
9 Posts 4 Posters 689 Views 2 Watching
  • 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.
  • 8 Offline
    8 Offline
    8Observer8
    wrote on 20 Dec 2024, 12:51 last edited by
    #1

    Hi,

    Qt Creator highlights these constructs as an error in a C project:

    776dab12-81b0-4ab4-86d2-0f485bb35c0c-image.png

    But it compiles without errors. When you hover your mouse over this line, a message appears: unexpected token 'struct'

    You can reproduce by creating an empty Non-Qt C project: File > New Project > Non-Qt Project > Plain C Application

    main.c

    #include <stdio.h>
    
    struct myStructure {
        int a;
        int b;
    };
    
    int main()
    {
        struct myStructure s = (struct myStructure){1, 2};
        return 0;
    }
    

    Maybe is the bug report already exist? Or should I create a new bug report?

    C 1 Reply Last reply 20 Dec 2024, 12:52
    0
    • 8 8Observer8
      20 Dec 2024, 12:51

      Hi,

      Qt Creator highlights these constructs as an error in a C project:

      776dab12-81b0-4ab4-86d2-0f485bb35c0c-image.png

      But it compiles without errors. When you hover your mouse over this line, a message appears: unexpected token 'struct'

      You can reproduce by creating an empty Non-Qt C project: File > New Project > Non-Qt Project > Plain C Application

      main.c

      #include <stdio.h>
      
      struct myStructure {
          int a;
          int b;
      };
      
      int main()
      {
          struct myStructure s = (struct myStructure){1, 2};
          return 0;
      }
      

      Maybe is the bug report already exist? Or should I create a new bug report?

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 20 Dec 2024, 12:52 last edited by
      #2

      @8Observer8 said in Fake error with structure:

      Or should I create a new bug report?

      What code model do you use? If it is not clang but the internal I don't think it's worth reporting a bug.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      8 1 Reply Last reply 20 Dec 2024, 13:23
      1
      • C Christian Ehrlicher
        20 Dec 2024, 12:52

        @8Observer8 said in Fake error with structure:

        Or should I create a new bug report?

        What code model do you use? If it is not clang but the internal I don't think it's worth reporting a bug.

        8 Offline
        8 Offline
        8Observer8
        wrote on 20 Dec 2024, 13:23 last edited by 8Observer8
        #3

        @Christian-Ehrlicher said in Fake error with structure:

        What code model do you use? If it is not clang but the internal

        I don't understand what do you mean. I've download Qt Creator 15.0.0 here: https://github.com/qt-creator/qt-creator/releases I have CMake 3.27 and MinGW 14.2: https://github.com/skeeto/w64devkit/releases. I just want to use pure C language with CMake. I've created a project like this:

        b0164e6d-2acb-4997-b39c-2e96f46fc618-image.png

        0804f311-1fd7-4159-a4b4-6cd5f7cc53aa-image.png

        J 1 Reply Last reply 24 Dec 2024, 11:24
        0
        • B Offline
          B Offline
          Bondrusiek
          wrote on 24 Dec 2024, 10:31 last edited by
          #4

          @8Observer8 ,
          The same behavior also occurs on macOS in Qt 6.7.3.

          1 Reply Last reply
          0
          • 8 8Observer8
            20 Dec 2024, 13:23

            @Christian-Ehrlicher said in Fake error with structure:

            What code model do you use? If it is not clang but the internal

            I don't understand what do you mean. I've download Qt Creator 15.0.0 here: https://github.com/qt-creator/qt-creator/releases I have CMake 3.27 and MinGW 14.2: https://github.com/skeeto/w64devkit/releases. I just want to use pure C language with CMake. I've created a project like this:

            b0164e6d-2acb-4997-b39c-2e96f46fc618-image.png

            0804f311-1fd7-4159-a4b4-6cd5f7cc53aa-image.png

            J Offline
            J Offline
            JonB
            wrote on 24 Dec 2024, 11:24 last edited by
            #5

            @8Observer8 , @Bondrusiek
            Creator, your project and compiler are not really the issue. You say the code compiles fine, what you see is internal to Creator editor IDE where it (tries to do) code completion for you. And it is apparently getting it wrong, happens. Go find what Code Completion you are using in Creator's settings. If that is clang it might be worth reporting an error, but if it is the old, internal one in Creator don't bother, try changing it to clang if you can.

            1 Reply Last reply
            0
            • B Offline
              B Offline
              Bondrusiek
              wrote on 24 Dec 2024, 11:59 last edited by
              #6

              I use this configurations:

              image.png

              and

              49f8bc97-f45e-4bef-b12e-00cefa3f12c8-image.png

              is it fine ?

              J 1 Reply Last reply 24 Dec 2024, 12:32
              0
              • B Bondrusiek
                24 Dec 2024, 11:59

                I use this configurations:

                image.png

                and

                49f8bc97-f45e-4bef-b12e-00cefa3f12c8-image.png

                is it fine ?

                J Offline
                J Offline
                JonB
                wrote on 24 Dec 2024, 12:32 last edited by
                #7

                @Bondrusiek , @8Observer8
                Ubuntu 24.04, Qt 6.4.2, Creator 13.0 from distro. I create a new Plain C project, I paste in @8Observer8's struct code above. I do not get any complaint/warning in the IDE.

                I have the same settings as your Installed Plugins.

                I think the relevant setting is Edit > Preferences > C++ > Clangd
                Screenshot 2024-12-24 122923.png

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  Bondrusiek
                  wrote on 24 Dec 2024, 13:33 last edited by
                  #8

                  image.png

                  Same thing with me too. If I checked the use clangd checkbox and the warning disappeared in the IDE. Thx for this info.

                  J 1 Reply Last reply 24 Dec 2024, 14:57
                  1
                  • B Bondrusiek
                    24 Dec 2024, 13:33

                    image.png

                    Same thing with me too. If I checked the use clangd checkbox and the warning disappeared in the IDE. Thx for this info.

                    J Offline
                    J Offline
                    JonB
                    wrote on 24 Dec 2024, 14:57 last edited by
                    #9

                    @Bondrusiek
                    If you do not Use clangd then it uses an old, internal one which is not maintained/changed much any longer.

                    1 Reply Last reply
                    0

                    1/9

                    20 Dec 2024, 12:51

                    • Login

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