Hello,
I am porting a Qt3 Custom widget from qt3 to qt4, building a plugin for it. This custom widget uses 2 images, "butterfly.png" and "qtlogo.png":
MyCanvasView
::MyCanvasView(QWidget *parent,
const char *name
) : Q3CanvasView(parent,name) {
myCanvas = new Q3Canvas(800,600);
myCanvas->setBackgroundColor ( c );//
myCanvas->setAdvancePeriod(30);
myCanvas->setDoubleBuffering(true);
this->setCanvas(myCanvas);
imageRTTI = 984376;
mainCount = 0;
butterflyimg = 0;
logoimg = 0;
tb = 0;
tp = 0;
QString butterfly_fn
= ":/images/butterfly.png";
butterflyimg[0].load( butterfly_fn );
butterflyimg[1] = butterflyimg[0].scaled(
int(butterflyimg[0].width()*0.75),
int(butterflyimg[0].height()*0.75) );
butterflyimg[2] = butterflyimg[0].scaled(
int(butterflyimg[0].width()*0.5),
int(butterflyimg[0].height()*0.5) );
butterflyimg[3] = butterflyimg[0].scaled(
int(butterflyimg[0].width()*0.25),
int(butterflyimg[0].height()*0.25) );
QString logo_fn
= ":/images/qtlogo.png";
logoimg[0].load( logo_fn );
logoimg[1] = logoimg[0].scaled( int(logoimg[0].width()*0.75),
int(logoimg[0].height()*0.75) );
logoimg[2] = logoimg[0].scaled( int(logoimg[0].width()*0.5),
int(logoimg[0].height()*0.5) );
logoimg[3] = logoimg[0].scaled( int(logoimg[0].width()*0.25),
int(logoimg[0].height()*0.25) );
}
void MyCanvasView::addButterfly()
{
[B]Q3CanvasPolygonalItem* i = new ImageItem(butterflyimg[rand()%4],myCanvas);[/B]
i->move(rand()%(myCanvas->width()-butterflyimg->width()),
rand()%(myCanvas->height()-butterflyimg->height()));
i->setZ(rand()%256+250);
i->show();
}
MyCanvasView::MyCanvasView(QWidget *parent, const char *name )
: Q3CanvasView(parent,name) {
myCanvas = new Q3Canvas(800,600);
QColor c(0,0,255);//
myCanvas->setBackgroundColor ( c );//
myCanvas->setAdvancePeriod(30);
myCanvas->setDoubleBuffering(true);
this->setCanvas(myCanvas);
imageRTTI = 984376;
mainCount = 0;
butterflyimg = 0;
logoimg = 0;
tb = 0;
tp = 0;
QString butterfly_fn = ":/images/butterfly.png";
butterflyimg = new QImage[4];
butterflyimg[0].load( butterfly_fn );
butterflyimg[1] = butterflyimg[0].scaled(
int(butterflyimg[0].width()*0.75),
int(butterflyimg[0].height()*0.75) );
butterflyimg[2] = butterflyimg[0].scaled(
int(butterflyimg[0].width()*0.5),
int(butterflyimg[0].height()*0.5) );
butterflyimg[3] = butterflyimg[0].scaled(
int(butterflyimg[0].width()*0.25),
int(butterflyimg[0].height()*0.25) );
QString logo_fn = ":/images/qtlogo.png";
logoimg = new QImage[4];
logoimg[0].load( logo_fn );
logoimg[1] = logoimg[0].scaled( int(logoimg[0].width()*0.75),
int(logoimg[0].height()*0.75) );
logoimg[2] = logoimg[0].scaled( int(logoimg[0].width()*0.5),
int(logoimg[0].height()*0.5) );
logoimg[3] = logoimg[0].scaled( int(logoimg[0].width()*0.25),
int(logoimg[0].height()*0.25) );
}
void MyCanvasView::addButterfly()
{
[B]Q3CanvasPolygonalItem* i = new ImageItem(butterflyimg[rand()%4],myCanvas);[/B]
i->move(rand()%(myCanvas->width()-butterflyimg->width()),
rand()%(myCanvas->height()-butterflyimg->height()));
i->setZ(rand()%256+250);
i->show();
}
To copy to clipboard, switch view to plain text mode
. The image files are here: (project folder)/images/(image file)
The code of my resources.qrc file used in the plugin is:
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>images/butterfly.png</file>
<file>images/qtlogo.png</file>
</qresource>
</RCC>
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>images/butterfly.png</file>
<file>images/qtlogo.png</file>
</qresource>
</RCC>
To copy to clipboard, switch view to plain text mode
The make file (.pro file from the plugin project) includes the line of the resource file:
RESOURCES = resources.qrc
RESOURCES = resources.qrc
To copy to clipboard, switch view to plain text mode
The plugin compiles, the c. widget appears in qtdesigner whith its methods and everything, it works.
I make a new project using this widget and I run it. The slots from the c. widget that do not need any resources work perfectly. But when I attempt to call the slots who need resources (images) to run, the images are not shown at all.
Why the images, correctly defined in the resources fil, are not being shown?
Bookmarks