Hi,
I am not expert in QT. I am trying to learn. I get a program from net and it is QT-3. I try to create in QT-4.3. Please help me to solve my problem. This code is from Qt-3 and I need to recreate it in QT-4.3. Please help me
code in QT-3
================================================== =====
#include <qimage.h>
#include <qshared.h>
class CVideoFrame
{
friend class CVideoDevice;
private:
struct VideoDataShared: public QShared
{
unsigned long sequence;
unsigned long time_stamp;
} *data;
uint m_Number;
private:
uint GetRefCount() const;
protected:
public:
CVideoFrame(const CVideoFrame &);
virtual ~CVideoFrame();
CVideoFrame &operator =(const CVideoFrame &);
uint GetNumber() const ;
void SetSequence(unsigned long seq);
unsigned long GetSequence() const;
void SetTimeStamp(unsigned long stamp);
unsigned long GetTimeStamp() const;
};
#include <qimage.h>
#include <qshared.h>
class CVideoFrame
{
friend class CVideoDevice;
private:
struct VideoDataShared: public QShared
{
const QImage *RGB;
const QImage *Y, *U, *V;
unsigned long sequence;
unsigned long time_stamp;
} *data;
uint m_Number;
private:
uint GetRefCount() const;
protected:
CVideoFrame(uint number, const QImage *rgb, const QImage *y, const QImage *u, const QImage *v);
public:
CVideoFrame(const CVideoFrame &);
virtual ~CVideoFrame();
CVideoFrame &operator =(const CVideoFrame &);
const QImage *GetRGB() const;
const QImage *GetY() const;
const QImage *GetU() const;
const QImage *GetV() const;
uint GetNumber() const ;
void SetSequence(unsigned long seq);
unsigned long GetSequence() const;
void SetTimeStamp(unsigned long stamp);
unsigned long GetTimeStamp() const;
};
To copy to clipboard, switch view to plain text mode
--------------------------------------------------------------------------------------------------------------------
#include "VideoFrame.h"
{
qDebug("CREATE DATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
data = new VideoDataShared;
if (data == 0)
return;
data->RGB = rgb;
data->Y = y;
data->U = u;
data->V = v;
data->sequence = 0;
data->time_stamp = 0;
m_Number = number;
qDebug(" m_Number is %d and number is %d >>>>>>>>>>>>>>>>>>>>",m_Number, number);
}
CVideoFrame::CVideoFrame(const CVideoFrame &f)
{
qDebug("SECOND CONSTRUCTORRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
data = f.data;
qDebug("time_stamp is %ld", data->time_stamp);
qDebug("sequence is %ld", data->sequence);
if (data != 0)
{
data->ref();
}
}
CVideoFrame::~CVideoFrame()
{
/* if (data && data->deref()) {
delete data;
data = 0;
}
*/
}
// private
uint CVideoFrame::GetRefCount() const
{
// if (data != 0)
// return 0;
return 1;
//// return data->count;
}
// public
CVideoFrame &CVideoFrame::operator =(const CVideoFrame &f)
{
//// if (f.data == 0)
//// return *this;
/* f.data->ref();
if (data && data->deref()) {
delete data;
data = 0;
}
data = f.data;
return *this;
*/
}
const QImage *CVideoFrame
::GetRGB() const {
/// qDebug("qDebuggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg %d",data->RGB);
return data->RGB;
}
const QImage *CVideoFrame
::GetY() const {
/////////// return data->Y;
}
const QImage *CVideoFrame
::GetU() const {
////////////// return data->U;
}
const QImage *CVideoFrame
::GetV() const {
//////////////// return data->V;
}
uint CVideoFrame::GetNumber() const
{
/// qDebug("<<m_Number is ..................%d<<",m_Number);
return m_Number;
}
void CVideoFrame::SetSequence(unsigned long seq)
{
//// data->sequence = seq;
}
/**
\brief Get sequence number
VideoFrames are sequentially numbered as they are fetches from videodevice
or file. The sequence number is a monotonous increasing number.
Note: when fetching frames from a video device, sequence numbers are not
contiguous in case frames are dropped by the capture process.
*/
unsigned long CVideoFrame::GetSequence() const
{
////////////// return data->sequence;
}
void CVideoFrame::SetTimeStamp(unsigned long stamp)
{
//////////////// data->time_stamp = stamp;
}
/**
\brief Get time stamp
\return Time in milliseconds
VideoFrames are time stamped, to make it easier to order/reference them. The
timestamp is measured in milliseconds.
Note: The first video frame of a video sequence is not guaranteed to have a
timestamp of 0! The only guarantee you have is that the timestamp is a monotonous
increasing number.
*/
unsigned long CVideoFrame::GetTimeStamp() const
{
///// return data->time_stamp;
}
#include "VideoFrame.h"
CVideoFrame::CVideoFrame(uint number, const QImage *rgb, const QImage *y, const QImage *u, const QImage *v)
{
qDebug("CREATE DATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
data = new VideoDataShared;
if (data == 0)
return;
data->RGB = rgb;
data->Y = y;
data->U = u;
data->V = v;
data->sequence = 0;
data->time_stamp = 0;
m_Number = number;
qDebug(" m_Number is %d and number is %d >>>>>>>>>>>>>>>>>>>>",m_Number, number);
}
CVideoFrame::CVideoFrame(const CVideoFrame &f)
{
qDebug("SECOND CONSTRUCTORRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
data = f.data;
qDebug("time_stamp is %ld", data->time_stamp);
qDebug("sequence is %ld", data->sequence);
if (data != 0)
{
data->ref();
}
}
CVideoFrame::~CVideoFrame()
{
/* if (data && data->deref()) {
delete data;
data = 0;
}
*/
}
// private
uint CVideoFrame::GetRefCount() const
{
// if (data != 0)
// return 0;
return 1;
//// return data->count;
}
// public
CVideoFrame &CVideoFrame::operator =(const CVideoFrame &f)
{
//// if (f.data == 0)
//// return *this;
/* f.data->ref();
if (data && data->deref()) {
delete data;
data = 0;
}
data = f.data;
return *this;
*/
}
const QImage *CVideoFrame::GetRGB() const
{
/// qDebug("qDebuggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg %d",data->RGB);
return data->RGB;
}
const QImage *CVideoFrame::GetY() const
{
/////////// return data->Y;
}
const QImage *CVideoFrame::GetU() const
{
////////////// return data->U;
}
const QImage *CVideoFrame::GetV() const
{
//////////////// return data->V;
}
uint CVideoFrame::GetNumber() const
{
/// qDebug("<<m_Number is ..................%d<<",m_Number);
return m_Number;
}
void CVideoFrame::SetSequence(unsigned long seq)
{
//// data->sequence = seq;
}
/**
\brief Get sequence number
VideoFrames are sequentially numbered as they are fetches from videodevice
or file. The sequence number is a monotonous increasing number.
Note: when fetching frames from a video device, sequence numbers are not
contiguous in case frames are dropped by the capture process.
*/
unsigned long CVideoFrame::GetSequence() const
{
////////////// return data->sequence;
}
void CVideoFrame::SetTimeStamp(unsigned long stamp)
{
//////////////// data->time_stamp = stamp;
}
/**
\brief Get time stamp
\return Time in milliseconds
VideoFrames are time stamped, to make it easier to order/reference them. The
timestamp is measured in milliseconds.
Note: The first video frame of a video sequence is not guaranteed to have a
timestamp of 0! The only guarantee you have is that the timestamp is a monotonous
increasing number.
*/
unsigned long CVideoFrame::GetTimeStamp() const
{
///// return data->time_stamp;
}
To copy to clipboard, switch view to plain text mode
================================================== ======
and I try to create it in QT-4 like this,
code in QT-4
================================================== =============
#include <QSharedData>
class CVideoFrame
{
friend class CVideoDevice;
private:
{
unsigned long sequence;
unsigned long time_stamp;
} *data;
uint m_Number ;
private:
uint GetRefCount() const;
protected:
public:
uint m_Number ;
CVideoFrame(const CVideoFrame &);
virtual ~CVideoFrame();
CVideoFrame &operator =(const CVideoFrame &);
int GetNumber() const ;
void SetSequence(unsigned long seq);
unsigned long GetSequence() const;
void SetTimeStamp(unsigned long stamp);
unsigned long GetTimeStamp() const;
};
#include <QSharedData>
class CVideoFrame
{
friend class CVideoDevice;
private:
struct VideoDataShared: public QSharedData
{
const QImage *RGB;
const QImage *Y, *U, *V;
unsigned long sequence;
unsigned long time_stamp;
} *data;
uint m_Number ;
private:
uint GetRefCount() const;
protected:
CVideoFrame(uint number, const QImage *rgb, const QImage *y, const QImage *u, const QImage *v);
public:
uint m_Number ;
CVideoFrame(const CVideoFrame &);
virtual ~CVideoFrame();
CVideoFrame &operator =(const CVideoFrame &);
const QImage *GetRGB() const;
const QImage *GetY() const;
const QImage *GetU() const;
const QImage *GetV() const;
int GetNumber() const ;
void SetSequence(unsigned long seq);
unsigned long GetSequence() const;
void SetTimeStamp(unsigned long stamp);
unsigned long GetTimeStamp() const;
};
To copy to clipboard, switch view to plain text mode
------------------------------------------------
#include <QtGui>
#include "VideoFrame.h"
{
data = new VideoDataShared;
if (data == 0)
return;
data->RGB = rgb;
data->Y = y;
data->U = u;
data->V = v;
data->sequence = 0;
data->time_stamp = 0;
m_Number = number;
}
CVideoFrame::CVideoFrame(const CVideoFrame &f)
{
data = f.data;
if (data != 0)
{
data->ref;
}
}CVideoFrame::~CVideoFrame()
{
/*if ( data && data->deref())
{
delete data;
data = 0;
}
*/
}
// private
uint CVideoFrame::GetRefCount() const
{
// if (data != 0)
// return 0;
return 1;
///////return data->count;
}
// public
CVideoFrame &CVideoFrame::operator =(const CVideoFrame &f)
{
// if (f.data == 0)
// return *this;
// f.data->ref;
///f.data->ref();
/* if (data && data->deref()) {
delete data;
data = 0;
}
*/
// data = f.data;
// return *this;
}
const QImage *CVideoFrame
::GetRGB() const {
return data->RGB;
}
const QImage *CVideoFrame
::GetY() const {
/////////////////////////// return data->Y;
}
const QImage *CVideoFrame
::GetU() const {
////////////////////////////// return data->U;
}
const QImage *CVideoFrame
::GetV() const {
///////////////////////// return data->V;
}
int CVideoFrame::GetNumber() const
{
return m_Number;
}
void CVideoFrame::SetSequence(unsigned long seq)
{
/////////////////////// data->sequence = seq;
}
unsigned long CVideoFrame::GetSequence() const
{
/////////////////////// return data->sequence;
}
void CVideoFrame::SetTimeStamp(unsigned long stamp)
{
//////////////////////// data->time_stamp = stamp;
}
unsigned long CVideoFrame::GetTimeStamp() const
{
///////////////// return data->time_stamp;
}
#include <QtGui>
#include "VideoFrame.h"
CVideoFrame::CVideoFrame(uint number, const QImage *rgb, const QImage *y, const QImage *u, const QImage *v)
{
data = new VideoDataShared;
if (data == 0)
return;
data->RGB = rgb;
data->Y = y;
data->U = u;
data->V = v;
data->sequence = 0;
data->time_stamp = 0;
m_Number = number;
}
CVideoFrame::CVideoFrame(const CVideoFrame &f)
{
data = f.data;
if (data != 0)
{
data->ref;
}
}CVideoFrame::~CVideoFrame()
{
/*if ( data && data->deref())
{
delete data;
data = 0;
}
*/
}
// private
uint CVideoFrame::GetRefCount() const
{
// if (data != 0)
// return 0;
return 1;
///////return data->count;
}
// public
CVideoFrame &CVideoFrame::operator =(const CVideoFrame &f)
{
// if (f.data == 0)
// return *this;
// f.data->ref;
///f.data->ref();
/* if (data && data->deref()) {
delete data;
data = 0;
}
*/
// data = f.data;
// return *this;
}
const QImage *CVideoFrame::GetRGB() const
{
return data->RGB;
}
const QImage *CVideoFrame::GetY() const
{
/////////////////////////// return data->Y;
}
const QImage *CVideoFrame::GetU() const
{
////////////////////////////// return data->U;
}
const QImage *CVideoFrame::GetV() const
{
///////////////////////// return data->V;
}
int CVideoFrame::GetNumber() const
{
return m_Number;
}
void CVideoFrame::SetSequence(unsigned long seq)
{
/////////////////////// data->sequence = seq;
}
unsigned long CVideoFrame::GetSequence() const
{
/////////////////////// return data->sequence;
}
void CVideoFrame::SetTimeStamp(unsigned long stamp)
{
//////////////////////// data->time_stamp = stamp;
}
unsigned long CVideoFrame::GetTimeStamp() const
{
///////////////// return data->time_stamp;
}
To copy to clipboard, switch view to plain text mode
================================================== =================
and in another function I call the function " frame->GetRGB() ". I think the error is this line.
void CImagePanelRGB::UpdateImage()
{
CVideoFrame *frame = 0;
frame = m_pVideo->GetLatestVideoFrame();
if (frame == 0){
}
else {
ImgRGB = frame->GetRGB()->copy(); //////////////check this line
}
delete frame;
update();
}
void CImagePanelRGB::UpdateImage()
{
CVideoFrame *frame = 0;
frame = m_pVideo->GetLatestVideoFrame();
if (frame == 0){
QImage *ImgRGB = new QImage();
}
else {
ImgRGB = frame->GetRGB()->copy(); //////////////check this line
}
delete frame;
update();
}
To copy to clipboard, switch view to plain text mode
-----------------------------------------------------------
Please help me to solve this problem
Bookmarks