如何过来出现以下错误?

时间:2013-12-18 06:45:49

标签: qt4

当我尝试在qt中创建相机应用程序时出现以下错误:

  

错误:没有匹配函数来调用'QWidget :: QWidget(const   QWidget *&,const char *&)'

3 个答案:

答案 0 :(得分:0)

我认为你误用了QWidget。 您应该阅读http://qt-project.org/doc/qt-5.0/qtwidgets/qwidget.html#QWidget

此外,如果你发送你的代码,它会有所帮助。


no matching function for call to ‘QSplashScreen::finish()’表示没有finish()方法。

http://qt-project.org/doc/qt-4.8/qsplashscreen.html#finish

答案 1 :(得分:0)

   ** .cpp ** #include <stdlib.h>

    #include <QApplication>
    #include <QWidget>
        #include <QTimer>
        #include <QPainter>
        #include <QMatrix>
        #include <QSplashScreen>
        #include <QFileDialog>
        #include <QPushButton>
       #include <QImage>
       #include <QPixmap>
       #include <QDateTime>
      //#include <QAudioOutput>
        //#include <QtMultimedia>

       #include "webcam.h"
       #include "SplashScreen.h"
       #include "mydialog.h"

       #define  VAL 0
       #define  VAL1    1

        static unsigned char huffman_table[] = {
                                    0xFF,0xC4,0x01,0xA2,0x00,0x00,0x01,0x05,0x01,0x01,0x01,0x01,
                                    0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,
                                    0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x01,0x00,0x03,
                                    0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,
                                    0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
                                    0x0A,0x0B,0x10,0x00,0x02,0x01,0x03,0x03,0x02,0x04,0x03,0x05,
                                    0x05,0x04,0x04,0x00,0x00,0x01,0x7D,0x01,0x02,0x03,0x00,0x04,
                                    0x11,0x05,0x12,0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07,0x22,
                                    0x71,0x14,0x32,0x81,0x91,0xA1,0x08,0x23,0x42,0xB1,0xC1,0x15,
                                    0x52,0xD1,0xF0,0x24,0x33,0x62,0x72,0x82,0x09,0x0A,0x16,0x17,
                                    0x18,0x19,0x1A,0x25,0x26,0x27,0x28,0x29,0x2A,0x34,0x35,0x36,
                                    0x37,0x38,0x39,0x3A,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,
                                    0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x63,0x64,0x65,0x66,
                                    0x67,0x68,0x69,0x6A,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,
                                    0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x92,0x93,0x94,0x95,
                                    0x96,0x97,0x98,0x99,0x9A,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,
                                    0xA9,0xAA,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xC2,
                                    0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xD2,0xD3,0xD4,0xD5,
                                    0xD6,0xD7,0xD8,0xD9,0xDA,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,
                                    0xE8,0xE9,0xEA,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,
                                    0xFA,0x11,0x00,0x02,0x01,0x02,0x04,0x04,0x03,0x04,0x07,0x05,
                                    0x04,0x04,0x00,0x01,0x02,0x77,0x00,0x01,0x02,0x03,0x11,0x04,
                                    0x05,0x21,0x31,0x06,0x12,0x41,0x51,0x07,0x61,0x71,0x13,0x22,
                                    0x32,0x81,0x08,0x14,0x42,0x91,0xA1,0xB1,0xC1,0x09,0x23,0x33,
                                    0x52,0xF0,0x15,0x62,0x72,0xD1,0x0A,0x16,0x24,0x34,0xE1,0x25,
                                    0xF1,0x17,0x18,0x19,0x1A,0x26,0x27,0x28,0x29,0x2A,0x35,0x36,
                                    0x37,0x38,0x39,0x3A,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,
                                    0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x63,0x64,0x65,0x66,
                                    0x67,0x68,0x69,0x6A,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,
                                    0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x92,0x93,0x94,
                                    0x95,0x96,0x97,0x98,0x99,0x9A,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,
                                    0xA8,0xA9,0xAA,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,
                                    0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xD2,0xD3,0xD4,
                                    0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,
                                              0xE8,0xE9,0xEA,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA};

         struct v4l2_buffer buf;
        unsigned int i,size,buf_size;
         char filename[] = "quickcam-0000.jpg";
           int dev, ret;
      FILE *file;
        void *mem;
          unsigned char data[65000];


       WebCam::WebCam( QWidget *parent, Qt::WindowFlags f)
              : QWidget( parent, f )

         {

            setWindowTitle("Project : Qt/E USB Camera Image capture");

            resize( QSize(320, 240).expandedTo(minimumSizeHint()) );
             //ClearState( State_Polished );

            video_open("/dev/video1");

            QPixmap pixmap("logo.png");

          // QSplashScreen* splash = new SplashScreen(pixmap);
             QSplashScreen splash(pixmap);
            splash.showMessage("Initialize...", 0,"Red");
            qApp->processEvents();

            sleep(3);

            splash.finish(QWidget *Pixmap);
            splash.deleteLater();

            video_set_format();
            video_reqbufs();
            map_the_buffers();
            Queue_the_buffers();
            video_enable(dev,1);
            start_streaming();
            changeBKImage();

            pmPaint = new QPixmap(320, 240);

            capt = new QTimer( this );
            capt->start(1);
            connect( capt, SIGNAL(timeout()), SLOT(slotTimeout()) );
        }

      WebCam::~WebCam()
      {

            qWarning("USB-WebCamera exit!! \n");
            capt->stop();
            video_enable(dev,0);
            munmap(mem,buf.length);
            close(dev);
    }

        void WebCam::start_streaming()
       {

            memset(&buf, 0, sizeof buf);
            buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
            buf.memory = V4L2_MEMORY_MMAP;
            ret = ioctl(dev, VIDIOC_DQBUF, &buf);
            if (ret < 0)
            {
                    printf("Unable to dequeue buffer (%d).\n", errno);
                    close(dev);
            }

            // Save the image.
            sprintf(filename, "/root/quickcam-%03u.jpg", VAL1);
            file = fopen(filename, "wb");
            if (file != NULL)
            {
                    unsigned char *input;
                    int input_size;
                    unsigned char *output;
                   // int output_data;
                    input = (unsigned char*)mem;
                    input_size=buf.bytesused;
                    int has_dht = 0;
                    output = data;
                    unsigned char hdr[4];
                    int o_count=0;
                    int r_count=0;
                    int size;
                    output[o_count++] = 0xFF;
                    output[o_count++] = 0xD8;
                    r_count += 2;

                    while(!has_dht)
                    {
                            memcpy(hdr, input+r_count, 4);
                            r_count += 4;

                            if(hdr[1]==0xC4) has_dht = 1;
                            else if(hdr[1]==0xDA) break;

                            // skip to the next marker
                            size = (hdr[2]<<8) + hdr[3];
                            memcpy(output+o_count, hdr, 4);
                            o_count += 4;

                            memcpy(output+o_count, input+r_count, size-2);

                            r_count += (size-2);
                            o_count += (size-2);
                    }

                    if(!has_dht)
                    {
                            memcpy(output+o_count, huffman_table, sizeof(huffman_table));
                            o_count += sizeof(huffman_table);
                            memcpy(output+o_count, hdr, 4);
                            o_count += 4;
                    }
                    // Process the remaining data in one go
                    memcpy(output+o_count, input+r_count, input_size-r_count);
                    o_count += (input_size-r_count);
                    r_count += (input_size-r_count);

                    input=NULL;
                    output=NULL;
                    fwrite(data,o_count,1,file);
                    fclose(file);
            }

            // Requeue the buffer.
            ret = ioctl(dev, VIDIOC_QBUF, &buf);
            if (ret < 0)
            {
                     printf("Unable to requeue buffer (%d).\n", errno);
                     close(dev);
            }

            fflush(stdout);
          }


       void WebCam::Queue_the_buffers()
        {
            memset(&buf, 0, sizeof buf);
            buf.index = VAL;
            buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
            buf.memory = V4L2_MEMORY_MMAP;
            ret = ioctl(dev, VIDIOC_QBUF, &buf);
            if (ret < 0)
            {
                    printf("Unable to queue buffer (%d).\n", errno);
                    close(dev);
            }
        }


        void WebCam::map_the_buffers()
        {
            memset(&buf, 0, sizeof buf);
            buf.index = VAL;
            buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
            buf.memory = V4L2_MEMORY_MMAP;
            ret = ioctl(dev, VIDIOC_QUERYBUF, &buf);
            if (ret < 0)
            {
                    printf("Unable to query buffer %u (%d).\n", VAL, errno);
                    close(dev);
            }

            printf("length: %u offset: %u\n", buf.length, buf.m.offset);

            mem = mmap(0, buf.length, PROT_READ, MAP_SHARED, dev, buf.m.offset);
            if (mem == MAP_FAILED)
            {
                    printf("Unable to map buffer %u (%d)\n", VAL, errno);
                    close(dev);
            }
            printf("Buffer %u mapped at address %p\n", VAL, mem);
        }

        int WebCam::video_set_format()
       {
            struct v4l2_format fmt;

            memset(&fmt, 0, sizeof fmt);
            fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
            fmt.fmt.pix.width = 320;
            fmt.fmt.pix.height = 240;
            fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
            fmt.fmt.pix.field = V4L2_FIELD_ANY;

            ret = ioctl(dev, VIDIOC_S_FMT, &fmt);
            if (ret < 0) {
                    printf("Unable to set format: %d.\n", errno);
                    return ret;
            }

            printf("Video format set: width: %u height: %u buffer size: %u\n",
                          fmt.fmt.pix.width, fmt.fmt.pix.height, fmt.fmt.pix.sizeimage);

            return 0;
        }

        int WebCam::video_reqbufs()
        {
            struct v4l2_requestbuffers rb;

            memset(&rb, 0, sizeof rb);
            rb.count = 16;
            rb.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
            rb.memory = V4L2_MEMORY_MMAP;

            ret = ioctl(dev, VIDIOC_REQBUFS, &rb);
            if (ret < 0)
            {
                 printf("Unable to allocate buffers: %d.\n", errno);
                 return ret;
            }

            printf("%u buffers allocated.\n", rb.count);
            return 0;
        }

        int WebCam::video_enable(int dev, int enable)
        {
            int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

            ret = ioctl(dev, enable ? VIDIOC_STREAMON : VIDIOC_STREAMOFF, &type);
            if (ret < 0) {
                    printf("Unable to %s capture: %d.\n", enable ? "start" : "stop", errno);
                    return ret;
            }

            return 0;
       }

        int WebCam::video_open(const char *devname)
        {
            struct v4l2_capability cap;

            dev = open(devname, O_RDWR);
            if (dev < 0) {
                    printf("Error opening device %s: %d.\n", devname, errno);
                    exit(1);
            }

            memset(&cap, 0, sizeof cap);
            ret = ioctl(dev, VIDIOC_QUERYCAP, &cap);
            if (ret < 0) {
                    printf("Error opening device %s: unable to query device.\n",devname);
                    close(dev);
                    return ret;
            }

            if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) {
                    printf("Error opening device %s: video capture not supported.\n",
                                    devname);
                    close(dev);
                    return -EINVAL;
            }

           printf("Device %s opened: %s.\n", devname, cap.card);
           return dev;
        }

        void WebCam::slotTimeout()
       {
            start_streaming();
            changepmBKImage();
            repaint(false);
       }

         void WebCam::paintEvent( QPaintEvent * )
       {
            QPainter painter(this);

            drawImage();

            painter.drawPixmap(0, 0, *pmPaint);
        }

         void WebCam::changepmBKImage()
        {
            QString strFilename;

            strFilename.sprintf("/root/quickcam-%03d.jpg", VAL1);

            if (!pmBk.load(strFilename)) {
                    qDebug("QPixmap load error\n");
            }
        }

        void WebCam::drawImage()
        {
            QMatrix matrix;
            QPainter painter;
            QString  strTime;

            matrix.scale(-1.0,1.0);
            pmBk=pmBk.xForm(matrix);
            pmPaint->resize(width(), height());
            painter.begin(pmPaint, this);

            painter.drawPixmap(QPoint(0, 0),pixmapBk);

            painter.end();

        }

     **.h file**
    #ifndef WEBCAM_H
#define WEBCAM_H


#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/select.h>

#include <QFileDialog>
#include <QPushButton>
#include <QPainter>
#include <QImage>
#include <QPixmap>
#include <QWidget>
#include <QDateTime>

#include <linux/videodev.h>
#include <linux/videodev2.h>


class WebCam : public QWidget
{
        Q_OBJECT
        public:
                WebCam( QWidget* parent=0,Qt::WindowFlags f=0 );
               // WebCam:: const char* name
               ~WebCam();
                QPushButton* Exit;
                QTimer *capt;

                int video_open(const char *devname);
                int video_set_format(void);
                int video_reqbufs(void);
                int video_enable(int dev, int enable);
                int fixup_jpeg1(unsigned char *input, int input_size, unsigned char *output);
                void map_the_buffers();
                void Queue_the_buffers();
                void start_streaming();
                int i,n;


        protected:
                void paintEvent( QPaintEvent *);
        private slots:
                void slotTimeout();


private:
    void drawImage();
    void changeBKImage();
    QTime time;
    QPixmap *pixmapBk;
    QPixmap *pmPaint;
    QImage CMOSImage;
    QFileDialog *fd;


};

#endif

答案 2 :(得分:0)

**errors**



/home/stesalit/Desktop/cam/webcam.cpp:90: error: no matching function for call to ‘QSplashScreen::finish()’

most repeating error
/home/stesalit/Desktop/cam/webcam.cpp:115: error: no matching function for call to ‘WebCam::close(int&)’


/home/stesalit/Desktop/cam/webcam.cpp:139: error: conflicting declaration ‘int output’
/home/stesalit/Desktop/cam/webcam.cpp:138: error: ‘output’ has a previous declaration as ‘unsigned char* output’
/home/stesalit/Desktop/cam/../../qtsdk-2009.05/qt/include/QtGui/qwidget.h:783: error: ‘QWidgetData* QWidget::data’ is private
/home/stesalit/Desktop/cam/webcam.cpp:141: error: within this context
/home/stesalit/Desktop/cam/webcam.cpp:141: error: cannot convert ‘QWidgetData*’ to ‘unsigned char*’ in assignment
/home/stesalit/Desktop/cam/../../qtsdk-2009.05/qt/include/QtGui/qwidget.h:783: error: ‘QWidgetData* QWidget::data’ is private
/home/stesalit/Desktop/cam/webcam.cpp:185: error: within this context
/home/stesalit/Desktop/cam/webcam.cpp:328: error: ‘changepmBKImage’ was not declared in this scope
/home/stesalit/Desktop/cam/webcam.cpp:329: error: no matching function for call to ‘WebCam::repaint(bool)’