【发布时间】:2013-09-07 18:22:02
【问题描述】:
我有两个功能。在一个函数中,我有一个QImage,然后我想将该 QImage 传递给另一个函数。这两个函数都有不同的参数。请告诉我该怎么做?
CMakeLists.txt
cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
rosbuild_init()
# Qt #####################################################
find_package(Qt4 REQUIRED)
set( QT_USE_QTGUI TRUE )
include(${QT_USE_FILE})
add_definitions (-DQT_NO_KEYWORDS)
# All source files
set(SELECTION_INTERFACE_SOURCE_CPP
src/SelectionInterface.cpp)
# All header files that use Qt Keywords (e.g. OBJECT)
set(SELECTION_INTERFACE_MOC_H
src/SelectionInterface.h
)
# Wrap for MOC
qt4_wrap_ui (SELECTION_INTERFACE_UI_H ${SELECTION_INTERFACE_UI})
qt4_wrap_cpp(SELECTION_INTERFACE_MOC ${SELECTION_INTERFACE_MOC_H})
rosbuild_add_library (selection_interface_lib
${SELECTION_INTERFACE_SOURCE_CPP}
${SELECTION_INTERFACE_MOC})
#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
rosbuild_add_executable(newtest_node src/SelectionInterface.cpp)
target_link_libraries (newtest_node selection_interface_lib ${QT_LIBRARIES})
生成文件
include $(shell rospack find mk)/cmake.mk
清单
<package>
<description brief="newTestCode">
newTestCode
</description>
<author>admin</author>
<license>BSD</license>
<review status="unreviewed" notes=""/>
<url>http://ros.org/wiki/newTestCode</url>
<depend package="roscpp"/>
<depend package="sensor_msgs"/>
<depend package="std_msgs"/>
</package>
SelectionInterface.h
#ifndef SELECTION_INTERFACE_H
#define SELECTION_INTERFACE_H
#include <QApplication>
#include <QtGui/QWidget>
#include <QtGui/QMenu>
#include <QtGui/QAction>
#include <QMainWindow>
#include <QDebug>
#include <QLabel>
#include <QGraphicsPixmapItem>
class Image:public QMainWindow
{
Q_OBJECT
public:
void getImage();
void displayImage();
QImage tempImage;
};
#endif
SelectionInterface.cpp
#include "SelectionInterface.h"
void Image::getImage()
{
QImage myImage("/home/usr/Pictures/image.jpg");
qDebug() << myImage.height();
tempImage= myImage.copy();
}
void Image::displayImage()
{
QImage finalImage = tempImage;
qDebug()<<finalImage.height();
}
int main (int argc, char** argv)
{
QApplication app(argc, argv);
Image object;
object.getImage();
object.displayImage();
object.show();
return app.exec();
}
【问题讨论】:
-
那么到底是什么问题呢? “我想将 QImage 从一个函数传递给另一个函数”对于 SO 来说太宽泛了。上面的代码似乎基本上可以传递图像:一种方法将 QImage 设置为成员变量,另一种方法使用它。它还有其他问题,但您似乎并没有询问它们。您需要帮助的问题是什么?另请阅读sscce.org
-
在另一个答案下的评论不是更新问题的好方法......无论如何,从疯狂的猜测部门,查看当前问题代码,尝试
this->tempImage而不是tempImage在所有方法中代码。我怀疑你的真实代码有另一个tempImage隐藏成员变量......(当然你不应该让成员变量被隐藏,其他变量应该有不同的名称,这只是一个快速测试)