天嵌 ARM开发社区

 找回密码
 注册
查看: 2301|回复: 5

LED灯测试程序问题

[复制链接]
348夏日里的春天 发表于 2012-4-17 13:55:52 | 显示全部楼层 |阅读模式
用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!" );
}

请问这是什么原因导致的错误,我是按天嵌手册做的
TQ-lkp 发表于 2012-4-17 13:58:37 | 显示全部楼层
环境变量啊
还是用的g++
:L
 楼主| 348夏日里的春天 发表于 2012-4-17 14:08:40 | 显示全部楼层
这个是我做的整个LED测试程序

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
 楼主| 348夏日里的春天 发表于 2012-4-17 15:02:18 | 显示全部楼层
TQ-lkp 发表于 2012-4-17 13:58
环境变量啊
还是用的g++

我做的是x86下的,环境变量设置了
[root@localhost Qte]# source setX86_QpeEnv
Makefile文件:
CC        =        gcc
CXX        =        g++
CFLAGS        =        -pipe -Wall -W -O2 -DNO_DEBUG
CXXFLAGS=        -pipe -DQWS -fno-exceptions -fno-rtti -Wall -W -O2 -DNO_DEBUG
INCPATH        =        -I$(QTDIR)/include -I$(QPEDIR)/include
LINK        =        g++
LFLAGS        =       
LIBS        =        $(SUBLIBS) -L$(QPEDIR)/lib -L$(QTDIR)/lib -lqpe -lqtopia -lqte
MOC        =        $(QTDIR)/bin/moc
UIC        =        $(QTDIR)/bin/uic

TAR        =        tar -cf
GZIP        =        gzip -9f

####### Files

HEADERS =        leds.h
SOURCES =        leds.cpp \
                main.cpp
OBJECTS =        leds.o \
                main.o \
       
INTERFACES =        leds.ui
UICDECLS =        leds.h
UICIMPLS =        leds.cpp
SRCMOC        =        moc_leds.cpp \
       
OBJMOC        =        moc_leds.o \
               
DIST        =       
TARGET = $(QPEDIR)/image/opt/Qtopia/bin/leds
DESKTOP = $(QPEDIR)/image/opt/Qtopia/apps/EmbedSky/leds.desktop
ICON = $(QPEDIR)/image/opt/Qtopia/pics/leds.png
INTERFACE_DECL_PATH = .

####### Implicit rules

.SUFFIXES: .cpp .cxx .cc .C .c

.cpp.o:
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.cxx.o:
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.cc.o:
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.C.o:
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.c.o:
        $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<

####### Build rules


all: $(TARGET)
        cp -f leds.desktop $(DESKTOP)
        cp -f leds.png $(ICON)

$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC)
        $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)

moc: $(SRCMOC)

tmake: Makefile

Makefile: leds.pro
        tmake leds.pro -o Makefile

dist:
        $(TAR) leds.tar leds.pro $(SOURCES) $(HEADERS) $(INTERFACES) $(DIST)
        $(GZIP) leds.tar

clean:
        -rm -f $(OBJECTS) $(OBJMOC) $(DESKTOP) $(ICON) $(TARGET)
        -rm -f *~ core

####### Sub-libraries


###### Combined headers


####### Compile

leds.o: leds.cpp \
                leds.h \
                leds.ui

main.o: main.cpp \
                leds.h \
                /opt/EmbedSky/Qte/x86-qtopia-2.2.0/qtopia/include/qtopia/qpeapplication.h

leds.h: leds.ui
        $(UIC) leds.ui -o $(INTERFACE_DECL_PATH)/leds.h

leds.cpp: leds.ui
        $(UIC) leds.ui -i leds.h -o leds.cpp



moc_leds.o: moc_leds.cpp \
                leds.h


moc_leds.cpp: leds.h
        $(MOC) leds.h -o moc_leds.cpp

 楼主| 348夏日里的春天 发表于 2012-4-17 20:14:15 | 显示全部楼层
哪位大侠帮帮啊,在线等
 楼主| 348夏日里的春天 发表于 2012-4-17 21:28:15 | 显示全部楼层
哎,解决了,是命名的问题,QT中的命名有讲究
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2024-9-28 13:23 , Processed in 1.033243 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表