Hello everyone :)
I'm trying to design a camera, getting lot of errors...here is my project in attachments...can anyone please help me in rectifying those errors???
Printable View
Hello everyone :)
I'm trying to design a camera, getting lot of errors...here is my project in attachments...can anyone please help me in rectifying those errors???
I think you might get more answers if you tell us what the error is and show us the offending piece of code instead of posting your whole large project. People might not be willing to spend their time unpacking your project, building it and going through the compilation log.
actually got many errors so attaches the project...anyway here is my code
Code:
#ifndef _SPLASHSCREEN_H_ #define _SPLASHSCREEN_H_ #include <QPixmap> #include <QWidget> #include <QSplashScreen> { private: QPixmap pix; public: void finish(); void repaint(); int alignment =Qt::AlignLeft, }; #endif
Code:
#include <QApplication> #include <QPainter> #include <QPixmap> #include <QSplashScreen> #include <QWidget> #include "SplashScreen.h" pix( pixmap ) { setBackgroundPixmap(pix); resize( pix.size() ); move( scr.center() - rect().center() ); show(); repaint(); } void SplashScreen::repaint() { qApp->processEvents(); } void SplashScreen::finish() { close(); } int alignment =Qt::AlignLeft, { QPixmap textPix = pix; painter.setPen(Qt::blue); r.setRect( r.x() + 10, r.y() + 10, r.width() - 20, r.height() - 20 ); painter.drawText( r, alignment, message ); setBackgroundPixmap( textPix ); repaint(); }
Code:
Code:
#include <QMessageBox> #include <QDir> #include <QComboBox> #include "mydialog.h" { lb1->setGeometry(10,10,200,70); QDir dir; dir.setCurrent( "./" ); dir.setNameFilter("*.jpg"); for(int i=0;i<(int)dir.count();i++) lb1->insertItem(dir[i]); connect(lb1,SIGNAL(selected(int)),this,SLOT(slotSelected(int))); connect(lb1,SIGNAL(highlighted(int)),this,SLOT(slotHighlighted(int))); } { return str; } void MyDialog::slotSelected(int index) { str = lb1->text(index); accept(); } void MyDialog::slotHighlighted(int index) { str = lb1->currentText(); }
Code:
#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> { Q_OBJECT public: // WebCam:: ~WebCam(); 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: private slots: void slotTimeout(); private: void drawImage(); void changeBKImage(); QTime time; QPixmap *pmBk; QPixmap *pmPaint; QImage CMOSImage; QFileDialog *fd; }; #endif // WEBCAM_H
[CODE]#include <QtGui/QApplication>
#include <QWidget>
//#include <unistd.h>
#include "webcam.h"
#include "SplashScreen.h"
#include "mydialog.h"
int main( int argc, char ** argv )
{
QApplication a( argc, argv );
WebCam *usbcam = new WebCam;
// a.setWidget(usbcam);
usbcam->show();
int result = a.exec();
delete usbcam;
return result;
}
Code:
#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 "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, ...........................................................,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]; { setWindowTitle("Project : Qt/E USB Camera Image capture"); //ClearState( State_Polished ); video_open("/dev/video1") // QSplashScreen* splash = new SplashScreen(pixmap); splash.showMessage("Initialize...", 0,"Red"); qApp->processEvents(); sleep(3); splash.finish(); splash.deleteLater(); video_set_format(); video_reqbufs(); map_the_buffers(); Queue_the_buffers(); video_enable(dev,1); start_streaming(); changeBKImage(); 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); } { 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.end(); }
Cool, but what is the error?
not only one....am getting many many errors,not getting cleared....Here is the screen shotAttachment 9864
Added after 14 minutes:
/home/stesalit/Desktop/cam/webcam.cpp:14: error: QAudioOutput: No such file or directory
/home/stesalit/Desktop/cam/webcam.cpp:70: error: no matching function for call to ‘QWidget::QWidget(const QWidget*&, const char*&)’
/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)’
Add QT += multimedia to your project file and rerun qmake. Remember, only the first error is significant, the rest may be merely a result of the compiler trying to recover from the first error.
Actually I'm new to qt si I dont know where to add that but tried some how :P
#include <QtGui/QApplication>
#include <QWidget>
//#include <unistd.h>
#include "webcam.h"
#include "SplashScreen.h"
#include "mydialog.h"
QT +=multimedia
int main( int argc, char ** argv )
{
QApplication a( argc, argv );
WebCam *usbcam = new WebCam;
// a.setWidget(usbcam);
usbcam->show();
int result = a.exec();
delete usbcam;
return result;
}
Added after 5 minutes:
HereCode:
// 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); }
"Project file" is the one with "pro" extension.
can I add in the beginning of the file??
actually I'm trying for this code from last 4days.This is the last day for me to go back to my sir...so asking for help
Added after 45 minutes:
I have done like this....is this the correct way??
<variable>activebuildconfiguration</variable>
<value type="QT +=multimedia">Debug</value>
</data>
<data>
I have included here in the pro file...still getting the errors.
QT += multimedia
TARGET = cam
TEMPLATE = app
SOURCES += main.cpp \
webcam.cpp \
SplashScreen.cpp \
mydialog.cpp
HEADERS += webcam.h \
SplashScreen.h \
mydialog.h
FORMS +=
OTHER_FILES += logo.png
Added after 47 minutes:
what does these mean and how to rectify these??
error: within this context
error: expected primary-expression before ‘int’
This is not the first error. Post the first error.
every thing got cleared finally left with these....
/home/stesalit/Desktop/cam/webcam.cpp:90: error: expected primary-expression before ‘)’ token
/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:142: error: within this context
/home/stesalit/Desktop/cam/webcam.cpp:142: error: cannot convert ‘QWidgetData*’ to ‘unsigned char*’ in assignment
/home/stesalit/Desktop/cam/webcam.cpp:348: error: request for member ‘load’ in ‘((WebCam*)this)->WebCam::pmBk’, which is of non-class type ‘QPixmap*’
/home/stesalit/Desktop/cam/webcam.cpp:360: error: request for member ‘xForm’ in ‘((WebCam*)this)->WebCam::pmBk’, which is of non-class type ‘QPixmap*’
/home/stesalit/Desktop/cam/webcam.cpp:361: error: ‘class QPixmap’ has no member named ‘resize’
/home/stesalit/Desktop/cam/webcam.cpp:364: error: expected primary-expression before ‘*’ token
/home/stesalit/Desktop/cam/webcam.cpp:366: error: expected primary-expression before ‘*’ token
You have a syntax error in webcam.cpp line #89 or #90.