问题
Is there something similar to explicit code regions for folding in Qt Creator:
#pragma region Region_1
void Test() {}
void Test2() {}
void Test3() {}
#pragma endregion Region_1
I can see folding for logical code blocks, but do not know how to explicitly set such a block. My version of Qt Creator is 2.4.1
回答1:
Currently not.
I think it is better to structure your code by using code anyways. The regions as also found in C# are imho a bad substitute for proper structuring and keeping things maintainable.
回答2:
I think you can do this:
Reformat your someclass.cpp
namespace ns
{
CClass::CClass() {}
CClass::~CClass() {}
void CClass::Test() {}
void CClass::Test2() {}
void CClass::Test3() {}
}
for example as
namespace ns // construction-destruction
{
CClass::CClass() {}
CClass::~CClass() {}
}
namespace ns // test-region
{
void CClass::Test() {}
void CClass::Test2() {}
void CClass::Test3() {}
}
回答3:
you can place your code in {} and write a comment for its name.
{ // RegionName
void Test() {}
void Test2() {}
void Test3() {}
}
回答4:
Now we can do this by:
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 }
回答5:
you can place your code in {} and write a comment for its name.
This WILL THROW "EXPECTED UN-QUALIFIED ID"
error.
来源:https://stackoverflow.com/questions/11295361/code-folding-pragma-region-in-qt-creator