'Code folding (#pragma region) in Qt creator
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
Solution 1:[1]
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() {}
}
Solution 2:[2]
you can place your code in {} and write a comment for its name.
{ // RegionName
void Test() {}
void Test2() {}
void Test3() {}
}
Solution 3:[3]
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 }
Solution 4:[4]
This is a bit old, I know, but it showed up when I myself was searching for a resolution to this problem so...
@ATatum_BlurPD said in Qt Creator C++ folding region:
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}
I don't have enough reputation here to post image-proof, but you can see them here
Solution 5:[5]
you can place your code in {} and write a comment for its name.
This WILL THROW "EXPECTED UN-QUALIFIED ID" error.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sheridan |
| Solution 2 | Kaveh Safavi |
| Solution 3 | TerribleDog |
| Solution 4 | AJ_Tatum_BlurPD |
| Solution 5 | Nikaido |
