环境:Qt 4.7.4
1. 在全局头文件 "global.h" 声明 extern 变量
#ifndef GLOBAL_H
#define GLOBAL_H
extern int ItemFlag;
#endif // GLOBAL_H
2. 在 "main.cpp" main{} 函数体之前定义上述变量
#include <QtGui/QApplication>
#include "mainwindow.h"
#include "global.h"
int ItemFlag = 0;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}