PDA

View Full Version : can't load picture



aoo7wangyan
13th July 2009, 09:33
i am a qt newer,i have already writtten the .qrc . why the picture not show?

QPixmap map(":\images\robot1.png");
ui.label->setPixmap(map);

.qrc
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="/">
<file>images/robot1.png</file>
</qresource>
</RCC>

Lykurg
13th July 2009, 09:40
Did you use Q_INIT_RESOURCE? And use slashes instead of back slashes.

caduel
13th July 2009, 09:41
use "/" as directory separator; if you insist on "\" you must at least escape the "\" properly

aoo7wangyan
13th July 2009, 12:19
QPixmap map(":/images/robot1.png");
it did not work,how to use Q_INIT_RESOURCE,
i added code in main(),but

QApplication a(argc, argv);
Q_INIT_RESOURCE(a);

there is a error "1>main.obj : error LNK2019: unresolved external symbol "int __cdecl qInitResources_a(void)" (?qInitResources_a@@YAHXZ) referenced in function _main"

Lykurg
13th July 2009, 12:27
,how to use Q_INIT_RESOURCE
This is all described in the docs. Please read them!

aoo7wangyan
13th July 2009, 12:32
i write code as doc,added Q_INIT_RESOURCE(a),but it did not work.

int main(int argc, char *argv[])
{
....
QApplication a(argc, argv);
Q_INIT_RESOURCE(a);
....
}

Lykurg
13th July 2009, 12:46
what's the full name of our qrc file. Have you altered you pro file?

aoo7wangyan
13th July 2009, 12:57
My enviroment is msvc in windows, how to alter my file?

Lykurg
13th July 2009, 13:01
My enviroment is msvc in windows

I have supposed that, but what I have meant is, what file name has you qrc file. And how to alter your pro file, you can read in the docs under the topic "The Qt Resource System" (-> RESOURCES)...

aoo7wangyan
13th July 2009, 14:59
thank you ,i solve it .it need change the .qrc file's properties in VS solution explorer.

command line:C:\Qt\4.5-msvc2008\bin\rcc.exe -name teach teach.qrc -o qrc_teach.cpp
description:RCC 222.qrc
outputs:qrc_teach.cpp
additional dependencies:C:\Qt\4.5-msvc2008\bin\rcc.exe;teach.qrc