How to type tab in Qt?

The TAB character literal can be written as ‘\t’ or ‘    ‘ in your C/C++ source code. They represent the same character. Character literals are enclosed in single quotes while string literals are enclosed in double quotes.

You can create QChar representing the TAB character as follows:

QChar c1('\t');
QChar c2('	');

The two characters c1 and c2 are equal. However, if you type the TAB character in Qt creator, you will find they are not equal. Meanwhile, you will find the warning message at the c2 line: multi-character character constant. Yes, the single quotes surrounded stuff is a multi-character character which includes 4 spaces. In other words, when you press TAB key while editing your source code in qt creator, the TAB key is replaced by four space characters. You’d better use the escaped representation of the TAB character \t here. But the tab behavior can be changed by “Tools/Options/C++/Code Style/General/Tab Policy:Tabs Only”. The default Tab Policy is “Spaces Only”. After you change the tab policy, you can type the TAB character directly in your source code.

If you like my content, please consider buying me a coffee. Buy me a coffeeBuy me a coffee Thank you for your support!
Posted in

Leave a Reply