最近新学QT,试着写代码,碰到信号和槽的问题,请大家帮助!
程序代码:
#include <QObject>
#include <QApplication>
class One:public QObject
{
Q_OBJECT
public slots:
void sl();
};
void One::sl()
{
printf("hello\n");
}
class Two:public QObject
{
Q_OBJECT
signals:
void sen();
};
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
One *one = new One;
Two *two = new Two;
QObject::connect(two,SIGNAL(sen()),one,SLOT(sl()));
emit two->sen();
return app.exec();
}
下面是编译产生的错误信息:
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.3.4/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.3.4/include/QtCore -I/usr/local/Trolltech/Qt-4.3.4/include/QtCore -I/usr/local/Trolltech/Qt-4.3.4/include/QtGui -I/usr/local/Trolltech/Qt-4.3.4/include/QtGui -I/usr/local/Trolltech/Qt-4.3.4/include -I. -I. -I. -o test.o test.cpp
test.cpp: In function ‘int main(int, char**)’:
test.cpp:20: error: ‘void Two::sen()’ is protected
test.cpp:30: error: within this context
make: *** [test.o] Error 1
这是什么错误?由什么引起的,请大家指点!在下在线等待!