Code folding (#pragma region) in Qt creator

梦想与她 提交于 2019-12-08 15:30:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!