Wednesday, September 21, 2016

QT C++ Tip: Code folding ( C# region equivalent )

Tip: Code folding

I build my applications using QTCreator.

It is a very nice environment but it lacks the ability to store all active editor settings. One thing that I use a lot is folding code, that way the edited file is easier to maintain. However each time I start the editor I again have to fold every function because these settings are not stored.

After some experimenting I found the following simple solution to this problem:

Right before the block that you want to fold you place the following define:
#define FOLDINGSTART {
and directly after the block you place:
#define FOLDINGEND }

Now you have created the ability to fold the complete block between FOLDINGSTART and FOLDINGEND. Of course it is still not stored but at least you don't have to manually fold all the seperate functions and other code fragments by hand.

Arie