I have release my program and package the program with installshield, and installed the package program on another PC that without QT and VS installed, everything is sames fine. I have a dialog to show image, this dialog can show jpg,png and other format image on my developing environment PC, however, it only show png image correctly on the other PC ! I had package the qgif4.dll, qjpeg4.dll and corresponding dlls to my program. the fellowing is my codes, these codes for showing images was rewriten as the QtDemo/SQL/Drill down example.
// ImageItem.cpp
#include "ImageItem.h"
{
setAcceptsHoverEvents(false);
timeLine.setDuration(150);
timeLine.setFrameRange(0, 150);
connect(&timeLine, SIGNAL(frameChanged(int)), this, SLOT(setFrame(int)));
connect(&timeLine, SIGNAL(finished()), this, SLOT(updateItemPosition()));
}
void CImageItem
::setItem(int w,
int h,
const QPixmap &pixmap
) {
m_nW = w, m_nH = h;
setPixmap(pixmap);
adjust();
}
{
if (z != 1.0)
{
z = 1.0;
updateItemPosition();
}
if (timeLine.
state() == QTimeLine::NotRunning) timeLine.start();
}
{
if (z != 0.0) z = 0.0;
if (timeLine.
state() == QTimeLine::NotRunning) timeLine.start();
}
void CImageItem::setFrame(int frame)
{
adjust();
QPointF center
= boundingRect
().
center();
translate(center.x(), center.y());
scale(1 + frame / 550.0f, 1 + frame / 550.0f); // here change the scale
translate(-center.x(), -center.y());
}
void CImageItem::adjust()
{
matrix.scale(m_nW/ boundingRect().width(), m_nH/ boundingRect().height());
setMatrix(matrix);
}
void CImageItem::updateItemPosition()
{
setZValue(z);
}
// ImageItem.cpp
#include "ImageItem.h"
CImageItem::CImageItem( QGraphicsItem *parent, QGraphicsScene *scene)
: QGraphicsPixmapItem(parent, scene)
{
setAcceptsHoverEvents(false);
timeLine.setDuration(150);
timeLine.setFrameRange(0, 150);
connect(&timeLine, SIGNAL(frameChanged(int)), this, SLOT(setFrame(int)));
connect(&timeLine, SIGNAL(finished()), this, SLOT(updateItemPosition()));
}
void CImageItem::setItem(int w,int h,const QPixmap &pixmap)
{
m_nW = w, m_nH = h;
setPixmap(pixmap);
adjust();
}
void CImageItem::hoverEnterEvent(QGraphicsSceneHoverEvent * /*event*/)
{
timeLine.setDirection(QTimeLine::Forward);
if (z != 1.0)
{
z = 1.0;
updateItemPosition();
}
if (timeLine.state() == QTimeLine::NotRunning)
timeLine.start();
}
void CImageItem::hoverLeaveEvent(QGraphicsSceneHoverEvent * /*event*/)
{
timeLine.setDirection(QTimeLine::Backward);
if (z != 0.0) z = 0.0;
if (timeLine.state() == QTimeLine::NotRunning)
timeLine.start();
}
void CImageItem::setFrame(int frame)
{
adjust();
QPointF center = boundingRect().center();
translate(center.x(), center.y());
scale(1 + frame / 550.0f, 1 + frame / 550.0f); // here change the scale
translate(-center.x(), -center.y());
}
void CImageItem::adjust()
{
QMatrix matrix;
matrix.scale(m_nW/ boundingRect().width(), m_nH/ boundingRect().height());
setMatrix(matrix);
}
void CImageItem::updateItemPosition()
{
setZValue(z);
}
To copy to clipboard, switch view to plain text mode
and ImageView.cpp is here:
#include "ImageView.h"
#include "ImageItem.h"
CImageView
::CImageView(int imgWidth,
int imgHight,
int offsetX,
int offsetY,
QWidget *parent
): QGraphicsView(parent
){
m_nW = imgWidth,m_nH = imgHight;
m_pImageItem = new CImageItem;
setScene(m_pGraphScene);
m_pImageItem->setPos(offsetX,offsetY);
m_pGraphScene->addItem(m_pImageItem);
setRect(imgWidth,imgHight,offsetX,offsetY);
}
CImageView::~CImageView()
{
}
void CImageView::setRect(int imgWidth,int imgHight,int offsetX,int offsetY)
{
int frameWidth = imgWidth + offsetX * 2 + 2;
int frameHight = imgHight + offsetY * 2 + 2;
m_pGraphScene->setSceneRect(0,0,imgWidth+2*offsetX, imgHight+offsetY*2);
}
void CImageView::showImage(const QString& szName)
{
if(!QFile::exists(szName
)) {
AlarmBox(tr("Image File 【%1】 Not Found!").arg(szName));
return ;
}
m_pImageItem
->setItem
(m_nW,m_nH,
QPixmap(szName
));
}
#include "ImageView.h"
#include "ImageItem.h"
CImageView::CImageView(int imgWidth,int imgHight,int offsetX,int offsetY,QWidget *parent): QGraphicsView(parent)
{
m_nW = imgWidth,m_nH = imgHight;
m_pGraphScene = new QGraphicsScene(this);
m_pImageItem = new CImageItem;
setScene(m_pGraphScene);
m_pImageItem->setPos(offsetX,offsetY);
m_pGraphScene->addItem(m_pImageItem);
setRect(imgWidth,imgHight,offsetX,offsetY);
}
CImageView::~CImageView()
{
}
void CImageView::setRect(int imgWidth,int imgHight,int offsetX,int offsetY)
{
int frameWidth = imgWidth + offsetX * 2 + 2;
int frameHight = imgHight + offsetY * 2 + 2;
m_pGraphScene->setSceneRect(0,0,imgWidth+2*offsetX, imgHight+offsetY*2);
}
void CImageView::showImage(const QString& szName)
{
if(!QFile::exists(szName))
{
AlarmBox(tr("Image File 【%1】 Not Found!").arg(szName));
return ;
}
m_pImageItem->setItem(m_nW,m_nH,QPixmap(szName));
}
To copy to clipboard, switch view to plain text mode
when I want to show a image, call showImage(path) instead. and on my main.cpp, I had setted envrionment path like this:
pathList.
append(QDir::current().
absolutePath()+"/plugins");
pathList.
append(QApplication::applicationDirPath()+"/plugins");
QStringList pathList=QApplication::libraryPaths();
pathList.append(QDir::current().absolutePath()+"/plugins");
pathList.append(QApplication::applicationDirPath()+"/plugins");
QApplication::setLibraryPaths(pathList);
To copy to clipboard, switch view to plain text mode
and in the program install folder, the files struct is like this:
D:\PROGRAM FILES\FLOWERDATABASE
│ DatabaseConfig.ini
│ FlowerDatabase.exe
│ Mainframe_zh.qm
│ Microsoft.VC90.CRT.manifest
│ msvcm90.dll
│ msvcp90.dll
│ msvcr90.dll
│
├─Backup
│ SQL2000_Init.bak
│ SQL2005_Init.bak
│
├─Config
│ style.txt
│
├─Database
└─Plugins
├─codecs
│ qcncodecs4.dll
│ qgif4.dll
│ qjpeg4.dll
│ qtiff4.dll
│ qtwcodecs4.dll
│
└─sqldrivers
qsqlite4.dll
qsqlmysql4.dll
qsqloci4.dll
qsqlodbc4.dll
It's sames everythis is OK, I don't know what's the matter! Anything help is appreciate!
Bookmarks