Ubuntu 12.04, Qt 4.8, OpenCv 2.4.3, PCL 1.6. Developing all via Qt Creator 2.5.2. All in 64 bits version.
I din't faced this issue until now, due to the fact I was dealing with image files in disk via "cv::imread(filename)" and then transferring its data to QImage -> QPixmap -> QLabel. NO problem with that.
Now, I need to load some images into Qt resource files. I created the proper .qrc via Qt Creator, and copied and registered image files in it. Well, If I try to load images from resources, it doesn't work:
QImage qi = QImage(":images/red.jpg");
if (qi.isNull())
{
QMessageBox::warning(this,"hey","hey");
}
Of course, at beginning I was struggling with resource names for an entire day. Until I decided to start other project, and copypasted the resource file, and the code that loads that QImage. In the test project, It works OK. (same computer, same IDE & Environment, but no OpenCV linking).
Seeing this, I decided to try this piece of code:
QString fn = QFileDialog::getOpenFileName(this,"Load image");
qi = QImage(fn);
if (qi.isNull())
{
QMessageBox::warning(this,"hey","hey");
}
In original code, this doesn't work! fn is loaded with right filename, but "qi = QImage(fn);" fails. In the Test program, this works as expected.
This is a big problem, because I want to set some icons in windows, and some images for several widgets and QSplashScreen. It's not very acceptable to copy image files into generated binaries folders and load them, assuming user will do nothing with them...
I must point again, that this is NOT a issue with Qt resource filename.
Is there some workaround or idea about this?
PD: I tried QPixmap(":images/red.jpg"); but program fails execution.
PD: Some project settings:
ResFiles.qrc:
<RCC>
<qresource prefix="/">
<file>images/red.png</file>
</qresource>
</RCC>
QOP.proj file:
#-------------------------------------------------
#
# Project created by QtCreator 2013-03-09T23:56:16
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = QOP
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
[several files more...]
HEADERS += mainwindow.h \
[several files more...]
FORMS += mainwindow.ui \
camwindow.ui \
dialogsetupcam.ui \
dialogtestcam_sr4k.ui \
dialogtestcam_pmdnano.ui \
dialogcommand_pmdnano.ui \
dialogcreatecam.ui
CONFIG += link_pkgconfig
PKGCONFIG += opencv
CONFIG += link_pkgconfig
PKGCONFIG +=
#Do not use this configuration to get PCL, some sublibraries aren't properly accesible, in example Visualizer
#CONFIG += link_pkgconfig
#PKGCONFIG += pcl_io-1.6
#PCL Headers
INCLUDEPATH += /usr/include/pcl-1.6\
/usr/include/flann/\
/usr/include/eigen3/\
/usr/include/openni/
#PCL Libraries
LIBS += -lpcl_common\
-lpcl_features\
-lpcl_filters\
-lpcl_geometry\
-lpcl_io\
-lpcl_kdtree\
-lpcl_keypoints\
-lpcl_octree\
-lpcl_registration\
-lpcl_sample_consensus\
-lpcl_search\
-lpcl_segmentation\
-lpcl_surface\
-lpcl_tracking\
-lpcl_visualization
#VTK Headers
INCLUDEPATH += /usr/include/vtk-5.8
#VTK Libraries
LIBS += -lQVTK\
-lvtkalglib\
-lvtkCharts\
-lvtkCommon\
-lvtkDICOMParser\
-lvtkexoIIc\
-lvtkFiltering\
-lvtkftgl\
-lvtkGenericFiltering\
-lvtkGeovis\
-lvtkGraphics\
-lvtkHybrid\
-lvtkImaging\
-lvtkInfovis\
-lvtkIO\
-lvtkmetaio\
-lvtkParallel\
-lvtkproj4\
-lvtkQtChart\
-lvtkRendering\
-lvtksys\
-lvtkverdict\
-lvtkViews\
-lvtkVolumeRendering\
-lvtkWidgets
RESOURCES += \
ResFiles.qrc
OTHER_FILES += \
images/red.png
A workaround I've thought is to load these images with some QFile class and "transfer" it to QImage. Can this be done?