[CMake] Qt 4.4.3 + VS 2008 Images don't load.
Dr. Schröder
letsgocrazy at gmx.de
Sat Oct 25 13:20:41 EDT 2008
Hi there,
I'm using Qt 4.4.3 Open Source edition with Visual Studio 2008 and Cmake 2.6
Whenever I try to load an Image in my Application it doesn't load. It does
not matter if I load it from a resource file or from the harddisc. It does
not matter which format it has (I tried a few). It does not matter if I load
it to a QPixmap or a QImage. There is simply nothing loaded afterwards.
The weirdest thing about this is, that everything works fine on the PC I
compile the program (Vista 64bit, VS 32bit). If I link the Image by using
the Qt resource system everything is fine. I can put the Executable anywhere
and the Image is loaded. If I put it to my WinXP laptop, the program runs
fine, but no Image is loaded.
Any Suggestions?
Thx in advance,
Patrick
CMakeLists.txt:
# Zunaechst einige Makros. Daran sollte sich niemand stoeren,
# sie dienen dazu eine saubere Verzeichnisstruktur aufzubauen.
# Ich empfehle beim setzen des Projektnamens weiter zu lesen.
SET (UI_OUT_DIR "./src/ui")
SET (MOC_OUT_DIR "./src/moc")
SET (RSC_OUT_DIR "./src/rsc")
# QT4_WRAP_UI(outfiles inputfile ... )
MACRO (QT4_WRAP_UI_OUT outfiles )
FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${UI_OUT_DIR})
FOREACH (it ${ARGN})
GET_FILENAME_COMPONENT(it ${it} ABSOLUTE)
GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)
SET(outfile ${CMAKE_CURRENT_BINARY_DIR}/${UI_OUT_DIR}/ui_${outfile}.h)
ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
COMMAND ${QT_UIC_EXECUTABLE} -o ${outfile} ${it}
MAIN_DEPENDENCY ${infile})
SET(${outfiles} ${${outfiles}} ${outfile})
ENDFOREACH (it)
ENDMACRO (QT4_WRAP_UI_OUT)
# QT4_WRAP_CPP(outfiles inputfile ... )
MACRO (QT4_WRAP_CPP_OUT outfiles )
FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${MOC_OUT_DIR})
FOREACH (it ${ARGN})
GET_FILENAME_COMPONENT(it ${it} ABSOLUTE)
GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)
SET(outfile
${CMAKE_CURRENT_BINARY_DIR}/${MOC_OUT_DIR}/moc_${outfile}.cpp)
ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
COMMAND ${QT_MOC_EXECUTABLE} -o ${outfile} ${it}
DEPENDS ${it})
SET(${outfiles} ${${outfiles}} ${outfile})
ENDFOREACH(it)
ENDMACRO (QT4_WRAP_CPP_OUT)
# QT4_ADD_STATIC_RESOURCES(outfiles inputfile ... )
MACRO (QT4_ADD_STATIC_RESOURCES outfiles )
FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${RSC_OUT_DIR})
FOREACH (it ${ARGN})
GET_FILENAME_COMPONENT(outfilename ${it} NAME_WE)
GET_FILENAME_COMPONENT(infile ${it} ABSOLUTE)
GET_FILENAME_COMPONENT(rc_path ${infile} PATH)
SET(outfile
${CMAKE_CURRENT_BINARY_DIR}/${RSC_OUT_DIR}/qrc_${outfilename}.cpp)
# parse file for dependencies
FILE(READ "${infile}" _RC_FILE_CONTENTS)
STRING(REGEX MATCHALL "<file>[^<]*" _RC_FILES "${_RC_FILE_CONTENTS}")
SET(_RC_DEPENDS)
FOREACH(_RC_FILE ${_RC_FILES})
STRING(REGEX REPLACE "^<file>" "" _RC_FILE "${_RC_FILE}")
SET(_RC_DEPENDS ${_RC_DEPENDS} "${rc_path}/${_RC_FILE}")
ENDFOREACH(_RC_FILE)
ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
COMMAND ${QT_RCC_EXECUTABLE}
ARGS -name ${outfilename} -o ${outfile} ${infile}
MAIN_DEPENDENCY ${infile}
DEPENDS ${_RC_DEPENDS})
SET(${outfiles} ${${outfiles}} ${outfile})
ENDFOREACH (it)
ENDMACRO (QT4_ADD_STATIC_RESOURCES)
# Der Name des Projekts
PROJECT( ProjektName )
# Die verwendete CMake Version (gibt eine Fehlermeldung, wenn nicht gesetzt)
cmake_minimum_required(VERSION 2.6)
# Mithilfe von SET() kann man Variablen definieren, oder ihre Definition
aendern.
# Hier definieren wir alle Quelldateien zur spaeteren Verwendung.
SET( PROJEKTNAME_SRCS
./src/main.cpp
./src/MainWindow.cpp
)
# Man muss die Header Dateien eigentlich nicht separat definieren, es dient
nur der
# Uebersicht
SET( PROJEKTNAME_HEADERS
# in dem Beispielprojekt gibt es nur einen Header und der wird als naechstes
angegeben
)
# Hier werden alle Header Dateien spezifiziert, die zu MOC_ files
umgewandelt werden sollen.
# Typischerweise alle, die Q_OBJECT enthalten.
SET( PROJEKTNAME_MOC_HDRS
./src/MainWindow.h
)
# Die .ui Dateien
SET( PROJEKTNAME_UIS
./ui/MainWindow.ui
)
# und letztendlich die Ressource Datei
SET( PROJEKTNAME_RCS
./rsc/ProjektName.qrc
)
# Warnungen aktivieren
# ADD_DEFINITIONS( -Wall )
# Qt Module, die geladen werden sollen. In diesem Fall nichts. QtCore und
QtGui sind Standard
# SET(
# QT_USE_QTOPENGL TRUE
# )
# Sucht Qt4
FIND_PACKAGE( Qt4 REQUIRED )
# QT_USE_FILE wurde von FIND_PACKAGE definiert und enthält den Pfad zu Qt
INCLUDE( ${QT_USE_FILE} )
# Fuegt statische resourcen hinzu
QT4_ADD_STATIC_RESOURCES( RC_SRCS ${PROJEKTNAME_RCS} )
# Erzeugt ui_*.h Dateien aus den gegebenen Designer Dateien.
QT4_WRAP_UI_OUT( UI_HDRS ${PROJEKTNAME_UIS} )
# Hiermit wird die Anweisung gegeben, die MOC_*.cpp Dateien zu erzeugen.
QT4_WRAP_CPP_OUT( MOC_SRCS ${PROJEKTNAME_MOC_HDRS} )
# Wir muessen die Generierten dateien zu den include Directories
hinzufuegen, um die Generierten .h Dateien
# dem Projekt hinzufügen zu koennnen.
INCLUDE_DIRECTORIES(
${CMAKE_BINARY_DIR}/${UI_OUT_DIR}
${CMAKE_BINARY_DIR}/${MOC_OUT_DIR}
${CMAKE_BINARY_DIR}/${RSC_OUT_DIR}
)
# Hier weisen wir CMake an, welche Dateien zur Anwendung hinzukompiliert
werden sollen
ADD_EXECUTABLE( ProjektName ${PROJEKTNAME_SRCS} ${PROJEKTNAME_HEADERS}
${PROJEKTNAME_MOC_HDRS} ${MOC_SRCS} ${RC_SRCS} ${UI_HDRS} )
# Zu guter Letzt muessen wir CMake mitteilen, welche Libraries fuer unsere
Anwendung benoetigt werden.
# FIND_PACKAGE hat QT_LIBRARIES schon fuer uns vorbereitet.
TARGET_LINK_LIBRARIES( ProjektName ${QT_LIBRARIES} )
More information about the CMake
mailing list