Qt C + + programming specification

Source: Internet
Author: User

One, the file naming rules.

1, one class corresponds to one. h and one. cpp file, with the same file name as the class name, and the case is consistent.

The exception class has a close relationship with other classes, or if other classes are only serving the primary class (one class is used and the other must), you can write to the same. h file, or embed it in the main class.

2, extension header file with. h,c source files with. cpp. c,c++ source files.

3, the name of the file with the class name, if there is no class, you can use all the first letter capitalized form.

4, the order in which the header files are arranged

1 //1, header file beginning comment, including author, function narration, change, time. 2 /*3 Name:myclass4 Author: * * *5 Note:6 */7 8 //2, header file prevents duplicate inclusion of macros9 #ifndef __myclass_h__Ten #define__myclass_h__ One  A //3, included header file -#include <QWidget> -  the //4, macro definition - #defineCamera_device "/dev/video0" -  - //5, Constant + Static Char*my_str="This is my first Blog"; -  + //6, other type declaration, external variable applied, typedef rename type.  A classQpushbutton; at extern intMu_number; -  - //7, struct, enum, Union - structmypictureinfo{ -  - }; in  - enummyseason{ to  + }; -  the Union mybook{ *  $ };Panax Notoginseng  - //8, definition of class the classmyclass{ +  A }; the  + //9, anti-Duplicate header file macro end, and its comments - #endif //MyClass End

5, the order in which the source files are arranged

// 1, file start comment // 2, included header file // 3, static variable // 4, definition of variable (global) // 5, Declaration/definition of a static function // 6, the implementation of the function of the class, according to the order defined in. h, // 7, end of file comment
View Code

6, header file contains, System header files, other SDK libraries, third party libraries used for <> use, internal custom header file with "".

"1" is used here to avoid using relative paths, you can use the Include variable to specify the header file directory.

"2" refers to header file order, System header file, third-party library header file, qt header file, custom header file.

"3" uses the C header file and is referenced with extern "C" {}.

"4" Avoid the use of redundant header files, if many changes caused some header files useless, please delete.

"5" can be used appropriately to avoid excessive introduction of header files through pre-declaration.

"6" Do not define variables in the header file to see if memory usage is caused.

"7" header files do not use namespaces, and two namespaces may have functions with the same name, resulting in run errors (this is difficult to find). To use, precede the function with a scope. or introduce namespaces in a range within a class.

Qt C + + programming specification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.