I just upgraded to QT Creator 5.3 and created a brand new QT Widgets Application project and am using the Microsoft VC++ compiler. All I have is a resource file with "logo.png" added (which opens in QT if I double click it), and a label that I am trying to set the background image for. The problem is that no matter what I do I cannot get the image to show up when the program is running. The only way I can get it to show the image is by not using the resource file and instead map directly to the file (ex. "c:/blah/blah/logo.png")
Also, if I set the background image in the UI designer, the background shows up in the IDE but NOT when I run the program. I have tried probably 20+ variations of the code, including resource file aliases as well as adding the files to the project directly, and nothing seems to work.
I'm not sure if there is a step I am missing, or if perhaps there is something that I have to do to get the project to compile the image.
Resources.qrc
<RCC>
<qresource prefix="/">
<file>logo.png</file>
</qresource>
</RCC>
loginform.cpp
QPixmap pixmap = QPixmap (":/logo.png");
ui->label->setPixmap( QPixmap(pixmap));
Project.pro
OTHER_FILES += \
logo.png
RESOURCES += \
Resources.qrc
After countless hours of trial, error, and mostly frustration, I have been able to resolve this issue by simply running qmake.
To do this I just right clicked on the project and clicked "Run qmake" and suddenly the image errors (as well as a few others) were resolved!
Related
I have imported a qml file say A in other qml say B. Whenever I make some changes in A , it doesn't reflect in the Application. I have to again clean and rebuild to view the changes i made, which is very time-consuming. Is there an easier and efficient way of doing this, so time could be saved .
Or another way of saying this is :
qrc files are not added to Makefile dependencies in debug_and_release mode
example
A.qml
Rectangle {
id:xyz
Button
{
id: ButtonA
}
}
B.qml
Rectangle{
A {
id:abc
}
}
I am using qt 4, qtquick 1.0.
You can make two independent qrc files, one for debug which is only includes resources like sounds, images, fonts and ... and another qrc for release which includes qml files too.
Then you can use point to the qml files relatively with your current working directory (could be set in Build & Run pane) without need to include them in qrc which requires time consuming compilation and linkage.
Also be aware, the root qml file should be pointed by relative (or absolute path) from C++ side, and no other changes are required to other qml files and they works perfectly on both release and debug mode
In your pro file :
debug {
RESOURCES = application_debug.qrc
}
!debug {
RESOURCES = application_release.qrc
}
You can install the new qt creator, it will solve the problem. Worked for me. I installed QT creator 4.8.7.
I want to be able to replace the existing standard icon with my own but I am unsure how to do so. I only started Qt one week ago so I don't know much about the application. In addition to this I looked at the Qt website but their method for adding an icon did not work on my computer.
Besides using a RC file (Windows) you may specify the icon directly using qmake.
win32: RC_ICONS = icon.ico
Make sure it detects the path correctly. In the provided case the icon resides in the project root directory right beside the project file.
For window icons you typically, if application wide applicable, use some method of QApplication.
...
QApplication app(argc, argv);
...
app.setWindowIcon(QIcon(":/icon");
...
which is consuming the resource file using the alias icon. Here is an example (res.qrc):
<RCC>
<qresource prefix="/">
<file alias="icon">icon.png</file>
</qresource>
</RCC>
More information on resources are here.
Perhaps try the function setWindowIcon function on the QWidget or QApplication.
I'm trying to include a SSL cert in the app deployment so we can connect to our server securely. I am able to add the files into our asset folder and our resources.qrc file and it works with debug deployment. However when I try to make a release build, it breaks and is unable to find the files.
I've ripped through the QT docs and SO, but everything I've tried has not worked.
Here is the excerpt from the .pro file:
`qmlFolder.source = qml
DEPLOYMENTFOLDERS += qmlFolder # comment for publishing
assetsFolder.source = assets
DEPLOYMENTFOLDERS += assetsFolder
# Add more folders to ship with the application here
QT += xml svg quick qml widgets
# resources.qrc
RESOURCES += resources.qrc # uncomment for publishing`
Here is my resources.qrc file:
<RCC>
<qresource prefix="/">
<file>qml</file>
<file>GandiStandardSSLCA2.crt</file>
<file>SSLcomDVCA_2.crt</file>
</qresource> </RCC>
Here is where I set the path: certPath = "://SSLcomDVCA_2.crt"; // Dev Cert
I got the path from right clicking the file. Again it works in a debug build, but not for release, so I believe it's not being packaged properly. Any hints or ideas how to proceed resolve this issue?
I've found the "issue" and the answer to my problem. Although I think the problem would be a QT bug or my understanding of string definition is wrong. I set the resource file called certs.qrc when I put the two certificates for dev and prod. I created the file definition and used the path I got by right clicking on the resource file and copying it's path. See below for the full definition of the SSL, hopefully this will serve as an example for QT SSL as well because I could barely find any of those either.
Here is my certs file without the 'RCC' header because it seems to break block quotes:
<qresource prefix="/certs">
<file>GandiStandardSSLCA2.crt</file>
<file>SSLcomDVCA_2.crt</file>
</qresource>
Below is the definition for that certificate file:
// SSL socket set up
QFile certFile(":/certs/GandiStandardSSLCA2.crt");
if(certFile.open(QIODevice::ReadOnly))
{
qDebug() << "File opened";
}
else {
qDebug() << "Boooo";
}
QSslCertificate cert(&certFile, QSsl::Pem);
forgotPwSocket = new QSslSocket(this);
forgotPwSocket->addCaCertificate(cert);
All this is currently functional. make sure you run qmake in order to get the resource files compiled.
So now, my explanation as to why I was having a problem. I was using a different deploy method before for the certs where I was deploying the entire assets folder. That works for Android by not iOS so I decided to go with qrc instead. While I was trying to implement the /assets folder deployment I was using an ifdef to define the string of the path depending on if it was iOS or Android. I removed the ifdef, and all my problems went away, it was now able to find the files at the path. The string is a member of my network object and I would define it at run time using the ifdef. During all my debugging, it was the correct path as shown in the inspector. Realizing that using the .qrc resource eliminated the need to define the path based on Android/iOS I hardcoded the path value as stated above. Once I did that, it started working. The path name is the same as it was in the debugger with the ifdef in place so I'm not sure why/where this was breaking. If anyone has any further insight it would be fantastic to hear. Hopefully this will help anyone having a similar issue or getting SSL working in QT in general!
I have a Qt5 desktop project and I added a "resource.qrc" file with the Qt Creator editor which created the following line into the project's .pro file:
RESOURCES = resource.qrc
I put a blank prefix and a png file (14x14) and I tried to use it like this:
QPixmap pixmap = QPixmap ("://my_image.png");
ui->combobox->addItem(QIcon(pixmap), "itemname");
The problem is: the icon won't show up!
The following works:
QPixmap pixmap(14,14);
pixmap.fill(QColor("red"));
ui->combobox->addItem(QIcon(pixmap), "itemname");
so the problem must be in the resource embedding process.. I noticed that the generated "exe" hasn't a resource section inside it... I don't have static linked external libraries, so I don't think I need the Q_INIT_RESOURCE(resource) macro (it gives me undefined external)
Update:
I'm posting here my qrc file:
<RCC>
<qresource prefix="/">
<file>my_image.png</file>
</qresource>
</RCC>
it's pretty simple and I don't understand why at runtime icons are not showing up
I had this same issue recently, where I malformed the resource string. If you are using a current version of Qt Creator, you can open your .qrc file for edit and then right-click the resource (in this case image) that you are trying to address, then click "Copy Resource Path to Clipboard". And voila, you have the correct resource string every time.
Qt Creator is awesome.
Hope this helps!
#Nikos C. gives you useful advice, but I think your main problem was that you didn't use the correct link to the resource.
In your code, you have:
QPixmap pixmap = QPixmap ("://my_image.png");
but, according to the documentation, it should be
QPixmap pixmap = QPixmap (":/my_image.png");
or you can give aliases to your resources, and use those instead.
Issue is solved is use rcc.exe
C:\root\QT>c:\root\QT\4.7.4\bin\rcc.exe Headless.qrc -o qtresources.cpp
During compilation you should have images in the path.
Create the qtresources.cpp file include this file in makefile or project. You should able to see the image.
i first time deployed my app outside of the visual studio compiler on clean pc .
and i have problem . first i dont see any images in my application
i use .png , *.gif,.ico file types i trying to add the :
qgif4.dll
qico4.dll
qjpeg4.dll
qjpeg4.lib
qmng4.dll
qsvg4.dll
the way im using my images is with *.qrc file and i was hoping it compile it as resource ( i really hope .. )
in the pro file i just added it like this:
RESOURCES += resources.qrc
and it looks like this:
<RCC>
<qresource prefix="/">
<file>images/image1.png</file>
<file>images/icon-loading.gif</file>
<file>images/filter.ico</file>
<file>images/icon_lp.png</file>
</qresource>
</RCC>
but with no good i still see blank instead of images .
also do i need one of the vs run times dll’s in my application?
msvcm90.dll
msvcp90.dll
msvcr90.dll
Thanks
The image plugins need to be in the right location for the Qt plugin loader to find them. Try putting them in an 'imageformats' directory next to your executable.
Use depedency walker to figure out which are the libraries linked to your application. This way put your application in a random directory, use the tool and you will see all missing references. these are the one you need to include.
Can you show the line of code where you use an image?