在网上找了个qt刷屏的程序,
下面是主要代码,在main函数中调用showSlot程序,以便读取图形文件,但是遇到了奇怪的问题,
程序在linux PC端运行良好,用的是usr/lib/qt-3.1
但是在自己编译的qt embedded 就不行,显示每次都进入了paintEvent中,但是屏幕上就是没有显示,连窗口都没有,而且不论在主函数中调用了多少次显示图像,都只显示最后一张图。
请大家帮忙看看可能是怎么回事。
#include "form1.h"
#include <qvariant.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qpainter.h>
#include <qstring.h>
#include <qfiledialog.h>
#include <stdio.h>
#include <unistd.h>
/*
* Constructs a Form1 as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*/
Form1::Form1( QWidget* parent, const char* name, WFlags fl )
: QWidget( parent, name, fl )
{
if ( !name )
setName( "Form1" );
pushButton2 = new QPushButton( this, "pushButton2" );
pushButton2->setGeometry( QRect( 230, 10, 91, 21 ) );
pushButton1 = new QPushButton( this, "pushButton1" );
pushButton1->setGeometry( QRect( 30, 10, 81, 21 ) );
languageChange();
resize( QSize(720, 480).expandedTo(minimumSizeHint()) );
clearWState( WState_Polished );
// signals and slots connections
connect( pushButton2, SIGNAL( released() ), this, SLOT( close() ) );
// connect( pushButton1, SIGNAL( released() ), this, SLOT( showSlot() ) );
}
/*
* Destroys the object and frees any allocated resources
*/
Form1::~Form1()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void Form1::languageChange()
{
setCaption( tr( "Form1" ) );
pushButton2->setText( tr( "&Quit" ) );
pushButton1->setText( tr( "&Show" ) );
}
bool Form1::showSlot(const char * newfilename)
{
bool ok = false;
ok = image.load((QString)newfilename, 0); //step 2
if (!ok)
{
printf("load image failed\n");
return false;
}
else printf("load %s success\n",newfilename);
ok = pm.convertFromImage(image, 0); //step 3
if (!ok)
{
printf("convert from image to a pixmap failed\n");
return false;
}
repaint();
return FALSE;
}
void Form1::paintEvent(QPaintEvent *pe)
{
printf("enter paint function\n");
QPainter painter(this);
painter.setClipRect(pe->rect());
painter.drawPixmap(0, 0, pm); //step 4
}