I have 2 images resouce files one for 96dpi, one for 120dpi. and i want to load these diffrent resouce(qrc)files at run time.
can u help me with example.i have searched it,but don't get exactly ,what i have to do.
I have 2 images resouce files one for 96dpi, one for 120dpi. and i want to load these diffrent resouce(qrc)files at run time.
can u help me with example.i have searched it,but don't get exactly ,what i have to do.
Do you create two rcc files along side your application or do you build both resources into the executable?
Cheers,
_
yes, i want to load resourc file at run time ,this is because i m try to develop high dpi application .and in my application i m set image at label.but after high dpi my image looks streched.thats y i want to load two diffrent resouce file at run time(normal, high dpi)with diffrent image sizes .
thanku
That would be possible with both images compiled in so I wanted to check if this is about loading resource files :-)
http://doc.qt.io/qt-5/resources.html...nary-resources
Cheers,
_
how to add images in .rcc file.
I am afraid I don't understand the question.
You add images to a Qt resource file like any other file.
Maybe you should read the whole section in the documentation on resources?
Cheers,
_
bartarya.parul (22nd July 2016)
one more thing is that.i m not able to load images of binary .rcc file at run time.
i generated two diffrent .qrc file,which same file name.like
res.qrc - i.png.
myres.qrc - i.png.
then run app
if(string=99)
{
set path=....res.qrc.
ui->label->setPixmap(QPixmap(":/i.png"));
}
else if(string=120)
{
set path=....myres.qrc.
ui->label->setPixmap(QPixmap(":/i.png"));
}
and label set i.png of res.qrc file always.
can u help now.
Added after 6 minutes:
can u help me with example.
Last edited by bartarya.parul; 22nd July 2016 at 13:45.
Create one qrc file like this :then use it :Qt Code:
<RCC> <qresource prefix="/99"> <file>i.png</file> </qresource> <qresource prefix="/120"> <file>i.png</file> </qresource> </RCC>To copy to clipboard, switch view to plain text modeorQt Code:
if(string==99) { } else if(string==120) { }To copy to clipboard, switch view to plain text modeQt Code:
To copy to clipboard, switch view to plain text mode
sorry but u don't get my point.
i only load diffrent .qrc (in which same image file name exist) at run time.
when i press 99 then .qrc1 images files should display,and when i press 120 then .qrc2 images(@2x)should display.
i dont want to change name of images.because there are 30+ images. in my qrc file.
thanku.
Think : what is a result of this expression ?
It assigns the value 99 to string, then returns truewhat is a result of this expression
If your qrc file contains 30+ images, what size are they? 99 or 120?i only load diffrent .qrc (in which same image file name exist) at run time.
when i press 99 then .qrc1 images files should display,and when i press 120 then .qrc2 images(@2x)should display.
i dont want to change name of images.because there are 30+ images. in my qrc file.
Do you not understand that the contents of qrc files are compiled into your program as binary resources. They are no different than source code C++ files in that way - they are compiled, and after they are compiled, your program no longer needs the qrc file at run time. So it makes no sense at all to say "I want to load qrc1 or qrc2" because your program can't load a qrc file and do anything with it. What you are asking for is not possible.
What Lesiok and others have been trying to tell you is that the only way you can load images with different resolution is to put them all into the same resource file and decide which one you want to load at run time.
If each or your 30+ files has the same name for 99 and 120 resolution, the qrc architecture allows that: you put them in different subdirectories of the resource file tree. This is exactly what Lesiok said a few posts ago. Go back and read it again:
Create one qrc file like this :
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
While you are of course correct that qrc files are used at built time to describe contents of the QResource system, it is possible to generate "binary resource" files and load them during runtime (see my link in comment #4).
That is the usual option, but see above.
Cheers,
_
d_stranz (26th July 2016)
Yes, had forgotten that. I doubt that the OP could overcome the logistics of deploying an app with external resources loaded at runtime.it is possible to generate "binary resource" files
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
this is my example code. my output is i get same image with diffrent dpi.Qt Code:
return; } file.close(); int iValue = strData.toInt(); if(iValue==120) { qrcFile="C:/Users/dev/Desktop/m_image/myres.qrc"; } else if(iValue==144) qrcFile="C:/Users/dev/Desktop/m_image/res/m_icon.qrc"; qDebug()<<qrcFile<<rccFileName<<rccPath; QStringList args; args << "-binary"; args << qrcFileInfo.fileName(); args << "-o" << rccPath; QProcess rccProc; bool isLoaded = false; int ret = -1; ret = rccProc.execute("rcc", args); { qDebug() << " Could not open file for writing"; return; } else qDebug()<<"open"; while(!filercc.atEnd()) qDebug() << filercc.readLine(); if (ret == 0) // rcc executed successfully { qDebug()<<ret<<qrcFileInfo.absolutePath(); qDebug()<<"second path--"<<rccPath; qDebug()<<isLoaded; if (isLoaded) }To copy to clipboard, switch view to plain text mode
thank u all.
Last edited by anda_skoa; 26th July 2016 at 09:32. Reason: missing [code] tags
if you require the file to exist at runtime, you could just load it directly.
But if we overlook that at the moment then we see that your are not trying to access any files from the loaded resource, so how did you arrive at the conclusion that it always loads the same one?
Cheers,
_
Wow. I was wrong about the deployment problem. Deploy different qrc files and deploy the resource compiler to compile the qrc files at runtime on the user's system. I should have thought of that when I posted my original answer.
After all, the OP's question was "different resource file at run time" and sure enough, there's a way to do it.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Somewhere, someone must be teaching that Qt resource files are the solution to every problem... Seems like a rash of posts related to resource files lately...![]()
I write the best type of code possible, code that I want to write, not code that someone tells me to write!
Bookmarks