- 论坛徽章:
- 0
|
下面这个程序是在QT中用posix线程来不断地循环显示jpg图片的程序,可是运行几十分钟就自动中止运行有时甚至系统都死了,终端没有任何信息打印出来,请各位帮忙看看什么原因
#include "mainwidget.h"
#include <pthread.h>
#include <unistd.h>
#include <fcntl.h>
#include <qtextcodec.h>
#include <qgbkcodec.h>
#include <time.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "spcaframe.h"
#include "spcav4l.h"
#include "utils.h"
//#include "stty.h"
//控制调试信息输出
//#define DEBUG
void paint_vd0( void *) ;
void * loop_event( void * ) ;
unsigned int buf_size( char * ) ;
QString mytr(char* buffer,int size)
{
QTextCodec* gbk=QTextCodec::codecForName("GBK" ;
return gbk->toUnicode(buffer,size);
}
MainWidget::MainWidget(QWidget *parent,const char *name) MainWindow(parent,name,Qt::WStyle_Customize | Qt::WType_TopLevel),myimage(0)
{
QFont f1("wenquanyi",32);
setFont( f1);
if( glo_init( ) )
printf("init error !\n " ;
}
MainWidget::~MainWidget()
{
}
int MainWidget::glo_init( void )
{
pthread_t loop_thread;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_create( &loop_thread, &attr, (void*(*)(void*))loop_event, this );
return 0 ;
}
void * loop_event( void *ptr )
{
pthread_t paint_vd0_thd;
MainWidget * cur_widget = (MainWidget *)ptr;
pthread_create( &paint_vd0_thd, NULL, (void*(*)(void*))paint_vd0, ptr ) ;
return 0 ;
}
void MainWidget::paintEvent( QPaintEvent *event )
{
QPainter painter(this);
setWFlags(getWFlags()|Qt::WRepaintNoErase);
painter.drawPixmap( 20, 30, Qpxp);
}
void paint_vd0( void *ptr )
{
MainWidget * cur_widget = (MainWidget *)ptr;
while(1)
{
cur_widget->refreshPixmap();
usleep(1000);
}
}
void MainWidget::refreshPixmap()
{
static int j=0,k=0;
if(j==0){
Qpxp.load("/tmp/14.jpg" ;
j++;
k++;
}
else{
Qpxp.load("/tmp/17.jpg" ;
j--;
k++;
}
if(k%100==0){
printf("have done %d\n",k );
}
repaint();
} |
|