PDA

View Full Version : Sames executable, different behaviours...



high_flyer
9th March 2006, 22:12
Hi,

I have the following problem:
I am coding a Qt4.1.0 project with KDevelop3.3.1 on KDE3.5.1, SUSE10.
In that project I have a dialog with a QLabel.
In my dialogs implementation (the dialog is design with designer), I added a setPixmap() to my label with an image.
Now:
If I start the application from the console, the pixmap in my QLabel does not show up.
If I start the application with "Execute main program" within KDevelop, it also , wont show the pixmap.
However, if I start the application with "Execute subproject" within KDevelop, the pixmap is shown. (the main project is the "subproject" then)

Since I had to reinstall my SUSE, there is a small chance it has to do with a somehow bad installation.
Therefore, I attach here my project, and if any one here has a similar system and could just built and run it and say if he gets the same behaviour would help to eliminate or confirm the option of bad OS.

Other then that, if anyone here has an idea what this could be, please share.

Thanks in advance.

jacek
9th March 2006, 22:27
imagePanel.label->setPixmap(QPixmap("round_blue.png")); //using resources didn't help
You are using a path that is relative to current working directory --- no wonder it sometimes doesn't want to show up.

Remove the leading slashes from paths in sharpeye.qrc and try QPixmap(":/res/bt_maximize_press.png").

jrideout
9th March 2006, 22:34
You aren't using the resource, you are using the files directly. since the paths you gave for the images were relative, it depends on the directory that you launch the appliction for the paths to match up.

To use the resources you need to prefix the path with a colon.

as in: setPixmap(QPixmap(":/res/round_blue.png"))

Also, I find that qt is more consistant if in the qrc file I use <qresource prefix="/" > rather than <qresource >

high_flyer
10th March 2006, 09:04
You are using a path that is relative to current working directory --- no wonder it sometimes doesn't want to show up.

Remove the leading slashes from paths in sharpeye.qrc and try QPixmap(":/res/bt_maximize_press.png").

The code you see here (in the attached zip) was my last try...
My original code was with resources (mybe parts ares still commented there).
So, the above code you suggested was the first thing I tried...
If you use my project with resouces the way you suggested above, does it work for you?
But never the less it looks like it really is a realtive/absolute path problem, which makes sense anyhow.
I'll look again in to it, maybe I had a stupid typo somewhere...
P.S
But what about when I choose a pixmap from designer?
Then I have no influence on the image path, I can only choose the file, but how the path is saved is totally up to designer, and that behaves also as I explained above...

Thanks!!

jacek
10th March 2006, 09:22
If you use my project with resouces the way you suggested above, does it work for you?
Of course it works --- read carefully the beginning of the last sentence in my previous post (the one about removing leading slashes).


But what about when I choose a pixmap from designer?
It should work too, but I had to fix .qrc at least once.

Here's example of my .qrc file:<RCC>
<qresource prefix="/" >
<file>data/ciexyz</file>
...
<file>icons/open.png</file>
...
</qresource>
</RCC>I can access these resources using ":/data/ciexyz" or ":/icons/open.png" and they work also with Designer.

high_flyer
10th March 2006, 18:16
Just wanted to say thank you to who responded.
I must have had some typo before when I used the resources...
Any way now it works as it should.
Thanks! :)

P.S
One more question though...
Why prefix "/" works for folders under my project root and not under the "real" root "/"?
This means that the qrc file always looks from its own location (or project root) and lower.:
so "/home/name" will be infact "project_location/home/name"...
But what if I have a general resource folder that is above my project root, what then?

I know in fact this is not the case, its not logical.
I know that prefix="/home/name" will indeed go to the right folder, not under my project, but why then "/" works?

jrideout
10th March 2006, 21:25
Just wanted to say thank you to who responded.
I must have had some typo before when I used the resources...
Any way now it works as it should.
Thanks! :)

You're welcome.


P.S
One more question though...
Why prefix "/" works for folders under my project root and not under the "real" root "/"?
This means that the qrc file always looks from its own location (or project root) and lower.:
so "/home/name" will be infact "project_location/home/name"...
But what if I have a general resource folder that is above my project root, what then?

I know in fact this is not the case, its not logical.
I know that prefix="/home/name" will indeed go to the right folder, not under my project, but why then "/" works?

The prefix has nothing to do with the filesystem. It is more like a namespace. You can define the prefix to be whatever, so that you avoid name collisions or for convenience. So prefix="/someRandomName", allows you to access :/someRandomName/myfile.png. This might be useful if you have multiple resource files each accessing their contents from paths that look the same with respect to their locations.

high_flyer
21st March 2006, 19:33
I need to revive this thread since i have again some problems with the resources...
I have some custom widget plugins that have pixmap properties.
In design time and preview all works as it should.
But at run time some pixmaps didn't show up while other pixmap properties did.
After exemining the ui and the uic generated code I found out that the pixmaps I choose in designer (from a resource file) are simply not being saved when I save the form.
So far I could not find an explanation for this, and was wondering if any of you might know what I might be doin to couse this?
As I said, the strange thing about this, is that its not for all pixmap properties, just for some...
This is the ui xml code where you can see a correct saved property:

<property name="maskPixmap" stdset="0" >
<pixmap resource="../sharpeye.qrc" >:/res/bt_zoom_plus1.png</pixmap>
</property>
And here a broken saved property:

<property name="firstStatePixmap" stdset="0" >
<pixmap/>
</property>
So no wonder the C++ generated code sets an empty QPixmap...

Any idea what I might be doing wrong to couse this, or can it be a bug?

Thanks.