Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt Creator C++ folding region



  • I am trying out C++ & Qt Creator. It looks like this is a forlorn hope, but we are now in 2020, is there still no equivalent of #region from C# or Python, or #pragma region from Visual Studio, etc., to define one's own folding regions in C++ code from Qt Creator? Personally I use these all the time. I see e.g. https://stackoverflow.com/questions/11295361/code-folding-pragma-region-in-qt-creator from 2012 or https://bugreports.qt.io/browse/QTCREATORBUG-5170 from 2011, but the suggested "workarounds" don't handle nearly enough cases. If it hasn't been done in a decade it doesn't look like it will get done now, does it...?


  • Qt Champions 2017

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

    It looks like this is a forlorn hope

    As is usual and proper with hope.

    is there still no equivalent of #region from C# or Python, or #pragma region from Visual Studio, etc., to define one's own folding regions in C++ code from Qt Creator?

    No, I don't believe so.

    Personally I use these all the time.

    That's on you, I for one don't long for such a feature. There's no (IDE) substitute for well structured code is my usual rationalization.

    If it hasn't been done in a decade it doesn't look like it will get done now, does it...?

    Unless you're up to the task of implementing it, I wouldn't hold my breath.


  • Qt Champions 2017

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

    It looks like this is a forlorn hope

    As is usual and proper with hope.

    is there still no equivalent of #region from C# or Python, or #pragma region from Visual Studio, etc., to define one's own folding regions in C++ code from Qt Creator?

    No, I don't believe so.

    Personally I use these all the time.

    That's on you, I for one don't long for such a feature. There's no (IDE) substitute for well structured code is my usual rationalization.

    If it hasn't been done in a decade it doesn't look like it will get done now, does it...?

    Unless you're up to the task of implementing it, I wouldn't hold my breath.



  • @kshegunov
    Thank you for replying. At least I know where I stand, and that I not missing some other workaround. I will accept your response and mark this as (sadly) closed.

    There's no (IDE) substitute for well structured code is my usual rationalization.

    My code is perfectly well structured & laid out, thank you :) You may be happy scrolling through lists of #includes or through, say, an adjacent list of half a dozen related functions within a class which are not to be regularly examined, but I am not. The fact that folding regions is incorporated into, say, Java, C#, Python and even Visual Studio C++ should indicate that I am not alone and that this is a common feature of modern IDEs! ;-)


  • Moderators

    @JonB if your goal is to use it as some kind of documentation, have you considered using https://doc.qt.io/qt-5/qdoc-index.html ? its the same thing that is used to (auto) generate Qt-Documentation

    🤗



  • @J-Hilk
    Thanks, but no, being a Real Programmer I am not, of course, looking to document anything I write ;-) No, what I am looking for is the ability to fold down related, adjacent areas of code so that I don't have to scroll through it on my screen. Purely as an example, if I have a few adjacent functions dealing with serialization/deserialization in a class, I like to fold these away under #region Serialization (which will collapse to one line, showing the Serialization word so I know what is there), and similarly with some other grouped functionality.


  • Qt Champions 2017

    You could split that off into a different translation unit, or even an included cpp, you know. :)
    It's a poor man's folding, I admit, but it sorta does what you want.



  • @kshegunov
    Yes I know I might be able to do that, but so could people in Java/Python/C#/VS C++, but they don't have to and there's a reason why... :)



  • @JonB You wil be happy to find out that you can do this!

    Goto tools>options>display>display>see image.

    a624b30a-76ba-4b9a-a3c2-b3d3226ca34b-image.png



  • @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?


  • Qt Champions 2017

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

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

    Yes, it does.



  • If you encapsulate in { }.



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


  • Moderators

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

    When IMHO it actually should!



  • @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!


Log in to reply