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. How to auto format my code
Forum Updated to NodeBB v4.3 + New Features

How to auto format my code

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
5 Posts 4 Posters 5.8k Views 1 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.
  • C Offline
    C Offline
    Circuits
    wrote on 24 May 2019, 21:39 last edited by
    #1

    I was looking through my options when it comes to auto formatting code with Qt Creator and so far I have been unsuccessful. I realize that I can press Ctrl-I in order to fix indentation issues but I am looking for more. I tried getting Clang Format:

    sudo apt-get install clang-format
    
    Help -> About plugins->Beautifier
    

    it told me to restart Qt so I did, then I set a macro:

    Tools -> Options -> Environment -> Keyboard
    

    I searched for: "Format Current File" and recorded my macro to be Ctrl Y

    then I went back to my code, messed with the formatting and then tried my new macro... nothing happened. So then I tried going back to Beautifier to try the different tools for the Enable auto format on file save option, none of which seemed to do anything to my code. The code I am attempting to format is qml, please help.

    S 1 Reply Last reply 25 May 2019, 13:34
    0
    • P Offline
      P Offline
      Pradeep P N
      wrote on 25 May 2019, 03:15 last edited by
      #2

      Hi @Circuits

      Below is the details how i did it in windows.
      Write the clang script as you wish to and include it in project. Or you can use the one available online for Qt

      # Clang-format configuration style to be used by Qt,
      # based on the rules from https://wiki.qt.io/Qt_Coding_Style and
      # https://wiki.qt.io/Coding_Conventions
      
      DISTFILES += \
            _clang-format
      

      Please also enable ClangCodeModule

      help -> About plugin ->  ClangCodeModule
      

      0_1558753285767_71af5026-fda7-429b-b5d8-805bdf11ca2e-image.png

      I Use LLVM for clang format and in Qt -> Tools -> Options -> Beautifier Set the Clang format command.

      0_1558753538255_66976584-0655-43dc-8aa6-fe2530f36970-image.png

      Then you can set the KeyBoard shortcut to it and it works.

      All the best.

      Pradeep Nimbalkar.
      Upvote the answer(s) that helped you to solve the issue...
      Keep code clean.

      1 Reply Last reply
      5
      • C Circuits
        24 May 2019, 21:39

        I was looking through my options when it comes to auto formatting code with Qt Creator and so far I have been unsuccessful. I realize that I can press Ctrl-I in order to fix indentation issues but I am looking for more. I tried getting Clang Format:

        sudo apt-get install clang-format
        
        Help -> About plugins->Beautifier
        

        it told me to restart Qt so I did, then I set a macro:

        Tools -> Options -> Environment -> Keyboard
        

        I searched for: "Format Current File" and recorded my macro to be Ctrl Y

        then I went back to my code, messed with the formatting and then tried my new macro... nothing happened. So then I tried going back to Beautifier to try the different tools for the Enable auto format on file save option, none of which seemed to do anything to my code. The code I am attempting to format is qml, please help.

        S Offline
        S Offline
        sierdzio
        Moderators
        wrote on 25 May 2019, 13:34 last edited by
        #3

        @Circuits said in How to auto format my code:

        The code I am attempting to format is qml, please help.

        Beautifier is for C++ only.

        To do some simple auto formatting, either select all text and press Ctrl + i, or use reformat QML/JS option as described in https://forum.qt.io/topic/32185/qml-code-beautifier

        (Z(:^

        C 1 Reply Last reply 31 May 2019, 14:27
        3
        • B Offline
          B Offline
          BaehtiH
          Banned
          wrote on 30 May 2019, 08:12 last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • S sierdzio
            25 May 2019, 13:34

            @Circuits said in How to auto format my code:

            The code I am attempting to format is qml, please help.

            Beautifier is for C++ only.

            To do some simple auto formatting, either select all text and press Ctrl + i, or use reformat QML/JS option as described in https://forum.qt.io/topic/32185/qml-code-beautifier

            C Offline
            C Offline
            Circuits
            wrote on 31 May 2019, 14:27 last edited by
            #5

            @sierdzio Ah I see, dang, I was hoping I could do extensive auto reformatting of qml code.

            1 Reply Last reply
            0

            1/5

            24 May 2019, 21:39

            • Login

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