我在“
mainwindow.h”中定义了
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void broadcastDatagram();
void netTest();
QStringList childlist;
QStringList childstatelist;
QStringList childnotelist;
然后在 “showlist.h”中
public:
explicit ShowList(QWidget *parent = 0);
~ShowList();
extern QStringList childlist;
extern QStringList childstatelist;
extern QStringList childnotelist;
并且在 “showlist.cpp"中引用,结果就出现了
错误:storage class specified for 'childlist'
/home/qust/qt/Server-build-desktop-Desktop_Qt_4_8_0_for_GCC__Qt_SDK____/../Server/showlist.h:18: 错误:storage class specified for 'childstatelist'
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void broadcastDatagram();
void netTest();
QStringList childlist;
QStringList childstatelist;
QStringList childnotelist;
然后在 “showlist.h”中
public:
explicit ShowList(QWidget *parent = 0);
~ShowList();
extern QStringList childlist;
extern QStringList childstatelist;
extern QStringList childnotelist;
并且在 “showlist.cpp"中引用,结果就出现了
错误:storage class specified for 'childlist'
/home/qust/qt/Server-build-desktop-Desktop_Qt_4_8_0_for_GCC__Qt_SDK____/../Server/showlist.h:18: 错误:storage class specified for 'childstatelist'
/home/qust/qt/Server-build-desktop-Desktop_Qt_4_8_0_for_GCC__Qt_SDK____/../Server/showlist.h:19: 错误:storage class specified for 'childnotelist'
其实这是个不能原谅的错误,extern只能找全局变量,我把变量声明在类里面,然后在类里面用extern当然是错的,
应该是这样的:
在mainwindow.h也就是在MainWindow类外
extern QStringList childlist;
extern QStringList childstatelist;
extern QStringList childnotelist;
然后在mainwindow.cpp开头或结尾等处:
QStringList childlist;
QStringList childstatelist;
QStringList childnotelist;
如果其他类想使用这3个变量的话,就得:
extern QStringList childlist;
extern QStringList childstatelist;
extern QStringList childnotelist;
感谢:feilinhe等高人指点。。