- A+
所属分类:C++
定义
StringTest.h文件
- #ifndef STRINGTEST_H
- #define STRINGTEST_H
- #include <QString>
- #define DEFINE_STR3 "string3"//方法3
- namespace DataType {//方法4
- extern QString ID;
- extern QString VALUE;
- }
- namespace Student {
- extern QString ID;
- extern QString NAME;
- }
- class StringTest
- {
- public:
- StringTest();
- ~StringTest();
- public:
- static const char* const str1;//方法1
- static const QString str2;//方法2
- };
- #endif // STRINGTEST_H
StringTest.cpp文件
- #include "stringtest.h"
- const char* const StringTest::str1 ="string1";
- const QString StringTest::str2 ="string2";
- namespace DataType {//方法4
- QString ID = "id";
- QString VALUE = "value";
- }
- namespace Student {
- QString ID = "id";
- QString NAME = "name";
- }
- StringTest::StringTest()
- {
- }
- StringTest::~StringTest()
- {
- }
应用
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- MainWindow w;
- w.show();
- qDebug()<<QStringLiteral("方法1")<<QString(StringTest::str1);
- qDebug()<<QStringLiteral("方法2")<<QString(StringTest::str2);
- qDebug()<<QStringLiteral("方法3")<<QString(DEFINE_STR3);
- qDebug()<<QStringLiteral("方法4")<<QString(Student::NAME);
- return a.exec();
- }