|
用qt2做led测试程序时,编译通过不了,报这样的错误:
[root@localhost LED]# make
g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -Wall -W -O2 -DNO_DEBUG -I/opt/EmbedSky/Qte/x86-qtopia-2.2.0/qt2/include -I/opt/EmbedSky/Qte/x86-qtopia-2.2.0/qtopia/include -o leds.o leds.cpp
In file included from leds.cpp:10:
leds.h:39: error: declaration of ‘virtual void leds::all_off()’
leds.h:35: error: conflicts with previous declaration ‘QPushButton* leds::all_off’
leds.h:40: error: declaration of ‘virtual void leds::all_on()’
leds.h:34: error: conflicts with previous declaration ‘QPushButton* leds::all_on’
leds.cpp: In constructor ‘leds::leds(QWidget*, const char*, uint)’:
leds.cpp:61: error: invalid use of member (did you forget the ‘&’ ?)
leds.cpp:62: error: invalid use of member (did you forget the ‘&’ ?)
leds.cpp:62: error: base operand of ‘->’ is not a pointer
leds.cpp:63: error: invalid use of member (did you forget the ‘&’ ?)
leds.cpp:63: error: base operand of ‘->’ is not a pointer
leds.cpp:65: error: invalid use of member (did you forget the ‘&’ ?)
leds.cpp:66: error: invalid use of member (did you forget the ‘&’ ?)
leds.cpp:66: error: base operand of ‘->’ is not a pointer
leds.cpp:67: error: invalid use of member (did you forget the ‘&’ ?)
leds.cpp:67: error: base operand of ‘->’ is not a pointer
leds.cpp:74: error: no matching function for call to ‘leds::connect(<unresolved overloaded function type>, const char [11], leds* const, const char [10])’
/opt/EmbedSky/Qte/x86-qtopia-2.2.0/qt2/include/qobject.h:110: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*)
/opt/EmbedSky/Qte/x86-qtopia-2.2.0/qt2/include/qobject.h:209: note: bool QObject::connect(const QObject*, const char*, const char*) const
leds.cpp:75: error: no matching function for call to ‘leds::connect(<unresolved overloaded function type>, const char [11], leds* const, const char [11])’
/opt/EmbedSky/Qte/x86-qtopia-2.2.0/qt2/include/qobject.h:110: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*)
/opt/EmbedSky/Qte/x86-qtopia-2.2.0/qt2/include/qobject.h:209: note: bool QObject::connect(const QObject*, const char*, const char*) const
leds.cpp:86: warning: statement has no effect
make: *** [leds.o] Error 1
[root@localhost LED]#
leds.h文件:
#ifndef LEDS_H
#define LEDS_H
#include <qvariant.h>
#include <qwidget.h>
class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QCheckBox;
class QGroupBox;
class QPushButton;
class leds : public QWidget
{
Q_OBJECT
public:
leds( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
~leds();
QGroupBox* LED_Test;
QCheckBox* led1;
QCheckBox* led2;
QCheckBox* led3;
QCheckBox* led4;
QPushButton* all_on;
QPushButton* all_off;
QPushButton* close;
public slots:
virtual void all_off();
virtual void all_on();
virtual void led1_p();
virtual void led2_p();
virtual void led3_p();
virtual void led4_p();
};
#endif // LEDS_H
leds.cpp文件
#include "leds.h"
#include <qcheckbox.h>
#include <qgroupbox.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qvariant.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "sys/ioctl.h"
#include "sys/stat.h"
#include <fcntl.h>
static int fd;
static char led1_s = 0, led2_s = 0, led3_s = 0, led4_s = 0;
/*
* Constructs a leds which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
*/
leds::leds( QWidget* parent, const char* name, WFlags fl )
: QWidget( parent, name, fl )
{
if ( !name )
setName( "leds" );
resize( 480, 272 );
setMaximumSize( QSize( 480, 272 ) );
setCaption( tr( "EmbedSky LED Test" ) );
LED_Test = new QGroupBox( this, "LED_Test" );
LED_Test->setGeometry( QRect( 72, 36, 241, 171 ) );
LED_Test->setTitle( tr( "LED Test" ) );
led1 = new QCheckBox( LED_Test, "led1" );
led1->setGeometry( QRect( 20, 30, 80, 20 ) );
led1->setText( tr( "LED1" ) );
led2 = new QCheckBox( LED_Test, "led2" );
led2->setGeometry( QRect( 20, 60, 80, 20 ) );
led2->setText( tr( "LED2" ) );
led3 = new QCheckBox( LED_Test, "led3" );
led3->setGeometry( QRect( 20, 90, 80, 20 ) );
led3->setText( tr( "LED3" ) );
led4 = new QCheckBox( LED_Test, "led4" );
led4->setGeometry( QRect( 20, 120, 80, 20 ) );
led4->setText( tr( "LED4" ) );
all_on = new QPushButton( LED_Test, "all_on" );
all_on->setGeometry( QRect( 160, 40, 71, 31 ) );
all_on->setText( tr( "All On" ) );
all_off = new QPushButton( LED_Test, "all_off" );
all_off->setGeometry( QRect( 160, 110, 71, 31 ) );
all_off->setText( tr( "All Off" ) );
close = new QPushButton( this, "close" );
close->setGeometry( QRect( 240, 210, 61, 31 ) );
close->setText( tr( "Close" ) );
// signals and slots connections
connect( all_on, SIGNAL( clicked() ), this, SLOT( all_on() ) );
connect( all_off, SIGNAL( clicked() ), this, SLOT( all_off() ) );
connect( led1, SIGNAL( stateChanged(int) ), this, SLOT( led1_p() ) );
connect( led2, SIGNAL( stateChanged(int) ), this, SLOT( led2_p() ) );
connect( led3, SIGNAL( stateChanged(int) ), this, SLOT( led3_p() ) );
connect( led4, SIGNAL( stateChanged(int) ), this, SLOT( led4_p() ) );
connect( close, SIGNAL( clicked() ), this, SLOT( close() ) );
system("/etc/rc.d/init.d/leds stop");
fd = open("/dev/EmbedSky-leds", O_RDWR);
if (fd < 0)
{
perror("open device EmbedSky-leds");
SLOT( close() );
}
for (int i=0;i< 4; i++)
{
ioctl(fd, 0, i);
}
}
/*
* Destroys the object and frees any allocated resources
*/
leds::~leds()
{
// no need to delete child widgets, Qt does it all for us
}
void leds::all_off()
{
for (int i = 0 ; i < 4; i ++)
{
ioctl(fd, 0, i);
}
led1->setChecked( 0); //修改led1 按钮的显示状态
led2->setChecked( 0);
led3->setChecked( 0);
led4->setChecked( 0);
//qWarning( "leds::all_off(): Not implemented yet!" );
}
void leds::all_on()
{
for (int i = 0 ; i < 4; i ++)
{
ioctl(fd, 1, i);
}
led1->setChecked( 1); //修改led1 按钮的显示状态
led2->setChecked( 1);
led3->setChecked( 1);
led4->setChecked( 1);
//qWarning( "leds::all_on(): Not implemented yet!" );
}
void leds::led1_p()
{
led1_s = ~led1_s;
// printf("led1_s = %d\n", led1_s);
if ( led1_s == 0)
ioctl(fd, 0, 0);
else
ioctl(fd, 1, 0);
// qWarning( "leds::led1_p(): Not implemented yet!" );
}
void leds::led2_p()
{
led2_s = ~led2_s;
// printf("led2_s = %d\n", led2_s);
if ( led2_s == 0)
ioctl(fd, 0, 1);
else
ioctl(fd, 1, 1);
//qWarning( "leds::led2_p(): Not implemented yet!" );
}
void leds::led3_p()
{
led3_s = ~led3_s;
// printf("led3_s = %d\n", led3_s);
if ( led3_s == 0)
ioctl(fd, 0, 2);
else
ioctl(fd, 1, 2);
// qWarning( "leds::led3_p(): Not implemented yet!" );
}
void leds::led4_p()
{
led4_s = ~led4_s;
// printf("led4_s = %d\n", led4_s);
if ( led4_s == 0)
ioctl(fd, 0, 3);
else
ioctl(fd, 1, 3);
//qWarning( "leds::led4_p(): Not implemented yet!" );
}
请问这是什么原因导致的错误,我是按天嵌手册做的
|
|