Qt resource not showing up in static build...
-
...when I build my app in debug/dynamic mode, I get one of my resources (an image) displaying just fine. When I build it in release/static, I don't see it.
I read a page about needing to explicitly reference resources when creating a static library but this is just an executable, so I don't think that applies. Any idea what I'm doing wrong?
-
Hi,
Are you talking about Q_INIT_RESOURCE ?
-
Yeah, mentioned here. But, if I'm reading the document correctly, that shouldn't apply to my example.
-
@mzimmers
Hi
You mean when you produce a static linked .exe ( with our own static compiled Qt) ( not the same as release mode vs debug mode )
the compiled in qres file does not work?And you have it in the project like ?
@mrjj yes on both counts. I am getting an error message at runtime:
QPixmap::scaled: Pixmap is a null pixmap
Here's the code I use to display it:
QPixmap logo(":/logos/logo1color.svg"); // .svg file created from .png file with http://www.autotracer.org/ QSize logoSize = ui->logoLabel->size(); ui->logoLabel->setPixmap(logo.scaled(logoSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
And again, it's working when built for debug.
-
@mrjj yes on both counts. I am getting an error message at runtime:
QPixmap::scaled: Pixmap is a null pixmap
Here's the code I use to display it:
QPixmap logo(":/logos/logo1color.svg"); // .svg file created from .png file with http://www.autotracer.org/ QSize logoSize = ui->logoLabel->size(); ui->logoLabel->setPixmap(logo.scaled(logoSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
And again, it's working when built for debug.
-
@mrjj yes on both counts. I am getting an error message at runtime:
QPixmap::scaled: Pixmap is a null pixmap
Here's the code I use to display it:
QPixmap logo(":/logos/logo1color.svg"); // .svg file created from .png file with http://www.autotracer.org/ QSize logoSize = ui->logoLabel->size(); ui->logoLabel->setPixmap(logo.scaled(logoSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
And again, it's working when built for debug.
Can you show your project's file structure? It probably is a path issue (difference) between the release and debug builds.
-
Also to be clear.
It does work in statically linked debug version but not in a
statically linked release version?
That is odd.
When you made your statically linkable Qt, you did use release mode? -
@mzimmers
Hi, svg is a normally plugin. maybe it was not compiled in ?
Did you try with a png or a more native image? -
Also to be clear.
It does work in statically linked debug version but not in a
statically linked release version?
That is odd.
When you made your statically linkable Qt, you did use release mode? -
@mrjj not quite: it works in dynamic/debug, but not in static/release. I haven't tried the other permutations yet.
-
Aha! So your debug is in fact dynamically linked. Then do the manual resource initialization as @SGaist hinted!
@kshegunov sorry - I thought I'd made that clear in my OP.
I've added this line to my main (my resource file is called "resources.qrc"):
Q_INIT_RESOURCE(resources);
Still doesn't show, and I'm getting that null pixmap error.
-
Do you have several resources named like that ?
-
@SGaist I'm not sure what you mean by "named like that," but I only have one .qrc file, and it only has two files in it.
Okay, can you grab a screenshot from the resource editor? Unless that path is an alias, then you need to put the image into that folder under the project. I personally always alias the things because it feels quite clumsy otherwise ...
-
So I need a subdirectory in my source folder? I'll try that.
EDIT: just moved logo to a subfolder, rebuilt and now I'm getting an error:
[release/qrc_resources.cpp] Error 1
So I deleted the moved file and re-added it. Still getting the null pixmap error.
-
So I need a subdirectory in my source folder? I'll try that.
EDIT: just moved logo to a subfolder, rebuilt and now I'm getting an error:
[release/qrc_resources.cpp] Error 1
So I deleted the moved file and re-added it. Still getting the null pixmap error.
@mzimmers said in Qt resource not showing up in static build...:
just moved logo to a subfolder, rebuilt and now I'm getting an error:
Not any subfolder, looking at the screenshot you need a folder called
logos
under your project root. Then readd the file and I think it should work. -
@mzimmers said in Qt resource not showing up in static build...:
just moved logo to a subfolder, rebuilt and now I'm getting an error:
Not any subfolder, looking at the screenshot you need a folder called
logos
under your project root. Then readd the file and I think it should work.@kshegunov no joy.
EDIT: put some text in here to separate the pics.
But at least now it's missing from both the debug and release versions...
-
@kshegunov no joy.
EDIT: put some text in here to separate the pics.
But at least now it's missing from both the debug and release versions...
But now your resource tree looks funny, you have two folders named "logos" there ...?
-
OK, I obviously don't know what's going on here. The resource editor requires me to add a prefix before I can add a file. When I add the file, if it's in a subdirectory, that gets prepended to the file name. This is why you're seeing what appears to be two levels of folders.
I don't know how to do this differently.