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 599 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.
  • 8Observer88 Offline
    8Observer88 Offline
    8Observer8
    wrote on 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?

    Christian EhrlicherC 1 Reply Last reply
    0
    • 8Observer88 8Observer8

      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?

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 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

      8Observer88 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        @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.

        8Observer88 Offline
        8Observer88 Offline
        8Observer8
        wrote on 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

        JonBJ 1 Reply Last reply
        0
        • BondrusiekB Offline
          BondrusiekB Offline
          Bondrusiek
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • 8Observer88 8Observer8

            @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

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on 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
            • BondrusiekB Offline
              BondrusiekB Offline
              Bondrusiek
              wrote on last edited by
              #6

              I use this configurations:

              image.png

              and

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

              is it fine ?

              JonBJ 1 Reply Last reply
              0
              • BondrusiekB Bondrusiek

                I use this configurations:

                image.png

                and

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

                is it fine ?

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on 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
                • BondrusiekB Offline
                  BondrusiekB Offline
                  Bondrusiek
                  wrote on 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.

                  JonBJ 1 Reply Last reply
                  1
                  • BondrusiekB Bondrusiek

                    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.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on 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

                    • Login

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