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. Qt Creator C++ folding region
Forum Updated to NodeBB v4.3 + New Features

Qt Creator C++ folding region

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 9 Posters 5.7k 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.
  • JonBJ JonB

    @JoeJoe_000
    I would be happy if that did it (don't have Qt Creator to hand atm), but surely it does not? Doesn't that just determine whether folding markers are visible or not, nothing to do with my question about wanting #region-type folding areas?

    kshegunovK Offline
    kshegunovK Offline
    kshegunov
    Moderators
    wrote on last edited by
    #10

    @JonB said in Qt Creator C++ folding region:

    Doesn't that just determine whether folding markers are visible or not

    Yes, it does.

    Read and abide by the Qt Code of Conduct

    1 Reply Last reply
    1
    • J Offline
      J Offline
      Justin Pattison-Schmidt
      wrote on last edited by
      #11

      If you encapsulate in { }.

      JonBJ 1 Reply Last reply
      0
      • J Justin Pattison-Schmidt

        If you encapsulate in { }.

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by JonB
        #12

        @Justin-Pattison-Schmidt
        You can't encapsulate multiple function definitions inside {}, nor lists of #include statements....

        J.HilkJ 1 Reply Last reply
        0
        • JonBJ JonB

          @Justin-Pattison-Schmidt
          You can't encapsulate multiple function definitions inside {}, nor lists of #include statements....

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #13

          @JonB you could encapsulate it in #ifdef and #endif but that won't make magically create folding markers either 🤷‍♂️

          When IMHO it actually should!


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          JonBJ 1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @JonB you could encapsulate it in #ifdef and #endif but that won't make magically create folding markers either 🤷‍♂️

            When IMHO it actually should!

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #14

            @J-Hilk
            I would be prepared to do that (well, probably #ifndef rather, so that I don't have to do anything for the code to still be active!). But if it doesn't give me my folding it doesn't help, does it? :)

            As you say, I checked an it does not fold at #if-ers. Lazy Creator! :( Even worse, I see that if the expression is false (e.g. #if 0) you lose the ability to fold the individual methods within it (presumably because it no longer has to examine/parse content). So if you have a large list of functions which are all #if-ed out for whatever reason, you then have to have all the code expanded and scroll through it all the time. Grrr!

            1 Reply Last reply
            1
            • A Offline
              A Offline
              ATatum_BlurPD
              wrote on last edited by
              #15

              I know this is old, but here is what works for me in QT Creator 4.13.3.

              • Make sure 'Display Folding markers' is enabled
                • 'Tools' -> 'Options' -> 'Text Editor' -> 'Display' tab
              • In the '.cpp' or '.h' file you want to add the region to:
                • Add '#pragma region RegionNameHere{'
                  • Note the '{' at the end
                • Add '#pragma endregion }'
                  • Note the '}' at the end

              Some sample code:

              #pragma region TIMER:Filter Change Delay {
              
              void CLog_EntryList::init_Timer_FilterChangeDelay()
              {
                  m_timerFilterChangeDelay.setInterval(5000);
                  m_timerFilterChangeDelay.setSingleShot(true);
                  connect(&m_timerFilterChangeDelay, &QTimer::timeout, this, &CLog_EntryList::slot_Timer_FilterChangeDelay_Timedout);
              }
              
              void CLog_EntryList::slot_Timer_FilterChangeDelay_Start()
              {
                  if(m_timerFilterChangeDelay.isActive())
                      return;
                  
                  m_timerFilterChangeDelay.setInterval(5000);
                  m_timerFilterChangeDelay.setSingleShot(true);
                  m_timerFilterChangeDelay.start();
              }
              
              void CLog_EntryList::slot_Timer_FilterChangeDelay_Timedout()
              {
                  
              }
              #pragma endregion}
              
              

              And some proof in the pudding:

              Not Folded

              76c18c84-1194-401c-8424-dbc67a058870-image.png

              Folded

              142a5887-7109-41b0-83f8-8730ee8cd440-image.png

              Enjoy ;)

              JonBJ 1 Reply Last reply
              7
              • A ATatum_BlurPD

                I know this is old, but here is what works for me in QT Creator 4.13.3.

                • Make sure 'Display Folding markers' is enabled
                  • 'Tools' -> 'Options' -> 'Text Editor' -> 'Display' tab
                • In the '.cpp' or '.h' file you want to add the region to:
                  • Add '#pragma region RegionNameHere{'
                    • Note the '{' at the end
                  • Add '#pragma endregion }'
                    • Note the '}' at the end

                Some sample code:

                #pragma region TIMER:Filter Change Delay {
                
                void CLog_EntryList::init_Timer_FilterChangeDelay()
                {
                    m_timerFilterChangeDelay.setInterval(5000);
                    m_timerFilterChangeDelay.setSingleShot(true);
                    connect(&m_timerFilterChangeDelay, &QTimer::timeout, this, &CLog_EntryList::slot_Timer_FilterChangeDelay_Timedout);
                }
                
                void CLog_EntryList::slot_Timer_FilterChangeDelay_Start()
                {
                    if(m_timerFilterChangeDelay.isActive())
                        return;
                    
                    m_timerFilterChangeDelay.setInterval(5000);
                    m_timerFilterChangeDelay.setSingleShot(true);
                    m_timerFilterChangeDelay.start();
                }
                
                void CLog_EntryList::slot_Timer_FilterChangeDelay_Timedout()
                {
                    
                }
                #pragma endregion}
                
                

                And some proof in the pudding:

                Not Folded

                76c18c84-1194-401c-8424-dbc67a058870-image.png

                Folded

                142a5887-7109-41b0-83f8-8730ee8cd440-image.png

                Enjoy ;)

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by JonB
                #16

                @ATatum_BlurPD
                I'm Creator 4.11.0. It works for the folding. Though it's only actually the { ... } doing that! You can just write

                #pragma {
                ...
                #pragma }
                

                and it folds just the same!

                Whatever I put there I get warning: ignoring #pragma { [-Wunknown-pragmas], so I'd have to switch off unknown pragmas warnings.

                So thank you, but it's obviously an unsupported hack. Which is fine for some but not for others.

                1 Reply Last reply
                1
                • R Offline
                  R Offline
                  Rafiz
                  wrote on last edited by Rafiz
                  #17

                  Oh, that's pretty fresh topic, and I look for same thing.
                  In code blocks, sublimetext and many other editors you could write

                  //{ description
                  int i;  //(or some other code ...)
                  //}
                  

                  and than you could collapse that code. But //{ won't work in qtCreator.
                  I'm not anyone qualified, but I think interpreting comments by editor isn't bad..
                  (I say so, as it looks qtCreator avoids that? {} after # aren't ignored and are interpreted (which - by the way - is kind of strange in my opinnion - like if I wanted to #define something_to_be { , it doesn't mean I want it to be folding block) )

                  So //{ is something I would suggest - as it's popular solution in other editors.
                  #pragma and/or #region would be cool too, but I just provide another idea

                  As for why I would use such thing - it's just that overloading all operators result in a lot of code, that I have to scroll through, code that I'm more often (than not) - not interested in looking at. Moving overloaded operators implementations to another .cpp is... Weird idea for me. And what is (and what's not) too much code to look through is very personal - so it's not about bad structure of code. For me even 200 lines is too much. I want less file to scroll/search through. Overloading operators use 40 of those lines in my case. And I wrote them caring more about lines used than about readibillity anyway (most of them are two-liners)

                  For now I think I will resolve to using big eye catching comment lines to know when I need to stop scrolling fast through some segment..

                  jsulmJ 1 Reply Last reply
                  0
                  • R Rafiz

                    Oh, that's pretty fresh topic, and I look for same thing.
                    In code blocks, sublimetext and many other editors you could write

                    //{ description
                    int i;  //(or some other code ...)
                    //}
                    

                    and than you could collapse that code. But //{ won't work in qtCreator.
                    I'm not anyone qualified, but I think interpreting comments by editor isn't bad..
                    (I say so, as it looks qtCreator avoids that? {} after # aren't ignored and are interpreted (which - by the way - is kind of strange in my opinnion - like if I wanted to #define something_to_be { , it doesn't mean I want it to be folding block) )

                    So //{ is something I would suggest - as it's popular solution in other editors.
                    #pragma and/or #region would be cool too, but I just provide another idea

                    As for why I would use such thing - it's just that overloading all operators result in a lot of code, that I have to scroll through, code that I'm more often (than not) - not interested in looking at. Moving overloaded operators implementations to another .cpp is... Weird idea for me. And what is (and what's not) too much code to look through is very personal - so it's not about bad structure of code. For me even 200 lines is too much. I want less file to scroll/search through. Overloading operators use 40 of those lines in my case. And I wrote them caring more about lines used than about readibillity anyway (most of them are two-liners)

                    For now I think I will resolve to using big eye catching comment lines to know when I need to stop scrolling fast through some segment..

                    jsulmJ Online
                    jsulmJ Online
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #18

                    @Rafiz You can file change request in Qt bug tracker: https://bugreports.qt.io/secure/Dashboard.jspa

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • Q Offline
                      Q Offline
                      Qtcpp_User
                      wrote on last edited by
                      #19

                      I agree wiht it. folding region could let codes look neat and organized without having to create more meaningless funtions and files and jump between them.
                      I saw someone use

                      #pragma region RegionName{
                      #pragma endregion}
                      

                      to fold codes.and enter text "-Wno-unknow-pragmas" in Tools->Options->C++->Code Model->Build-system warings(Paul)-> Build-system warnings->Copy->(give the configuration name)->(Choose your configuration)->(tick) Use diagnostic flags from build system, to avoid generating warnings.

                      1 Reply Last reply
                      1

                      • Login

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